Skip to content

Latest commit

 

History

History
79 lines (62 loc) · 2.08 KB

readme.md

File metadata and controls

79 lines (62 loc) · 2.08 KB

Vehicle Identification Number utilities

Maven Central

Library to generate and validate VIN's

Add to project in pom.xml

<dependency>
    <groupId>com.github.mkyrychenko</groupId>
    <artifactId>vin-utils</artifactId>
    <version>1.1.0</version>
</dependency>

For other languages look at Maven Central

Usage

To generate or validate some VIN, just call corresponding static methods

import de.kyrychenko.utils.vin.VinValidatorUtils;
import de.kyrychenko.utils.vin.VinGeneratorUtils;

class MyClass {
    public String generate(){
        return VinGeneratorUtils.getRandomVin();
    }

    public boolean validate(final String vin){
        return VinValidatorUtils.isValidVin(vin);
    }
}

To expose exceptions of validation, use VinUtils.validate(vin) instead of VinUtils.isValidVin(vin).

In case of wrong VIN, the InvalidVinException containing information, why validation has been failed, will be thrown.

The exception handling should be implemented in this case.

...
    public boolean validate(final String vin) throws InvalidVinException {
        return VinValidatorUtils.validateVin(vin);
    }
...

In applications, using validation constrains (Spring for example), integrate VIN validation due marking the field, method or parameter with @VIN annotation in validation context.

In Spring the POJO's, that should be validated looks like

class MyPojo {
    @NotNull
    private String id;
    
    @VIN
    private String id;
}

or method param

@RestController
class MyController {

    @PostMapping("/{vin}")
    public saveVin(final @Valid @VIN @PathVariable("vin") String vin){
        // do my things
    }
}

Information for maintainer available in the description of deployment process