{"id":18015594,"url":"https://github.com/nomemory/java-bean-validation-extension","last_synced_at":"2025-06-27T07:34:52.067Z","repository":{"id":52721799,"uuid":"106525102","full_name":"nomemory/java-bean-validation-extension","owner":"nomemory","description":"A library that extends the Java Bean Validation with additional @Annotations.","archived":false,"fork":false,"pushed_at":"2021-04-20T08:17:22.000Z","size":300,"stargazers_count":124,"open_issues_count":5,"forks_count":24,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-08T01:12:42.585Z","etag":null,"topics":["bean-validation","java","jsr380"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nomemory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-11T08:13:36.000Z","updated_at":"2024-12-21T09:50:59.000Z","dependencies_parsed_at":"2022-08-21T22:00:21.227Z","dependency_job_id":null,"html_url":"https://github.com/nomemory/java-bean-validation-extension","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nomemory/java-bean-validation-extension","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Fjava-bean-validation-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Fjava-bean-validation-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Fjava-bean-validation-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Fjava-bean-validation-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nomemory","download_url":"https://codeload.github.com/nomemory/java-bean-validation-extension/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nomemory%2Fjava-bean-validation-extension/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262213050,"owners_count":23276037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bean-validation","java","jsr380"],"created_at":"2024-10-30T04:14:29.036Z","updated_at":"2025-06-27T07:34:52.027Z","avatar_url":"https://github.com/nomemory.png","language":"Java","readme":"# java-bean-validation-extension (JBVExt)\n\n*JBVE* (Java Bean Validation Extension) is a small utils library that extends the [Java Bean Validation Specification](http://beanvalidation.org) with additional @Annotations. \n\nIf you are not familiar with JSR-380 (or the Java Bean Validation Specification) please follow [this nice tutorial](http://www.baeldung.com/javax-validation) first.\n\nIf you want to see *JVBExt* at work please:\n- read this [blog article](http://andreinc.net/2017/10/02/writing-an-unified-validation-mechanism-for-rest-apis-using-spring-boot-and-jsr-380/);\n- check out this [repository](https://github.com/nomemory/spring-boot-jbvext-example).\n\n## Installing the library\n\nFor versions (`\u003e=0.0.12`):\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.andreinc\u003c/groupId\u003e\n  \u003cartifactId\u003ejbve\u003c/artifactId\u003e\n  \u003cversion\u003e0.0.12\u003c/version\u003e\n\u003c/dependency\u003e\n```\n*Important note(s):*\n\nIn the runtime environment you will an existing JSR-380 implementation in the classpath. Spring Boot started web comes by default with [Hibernate Validator](http://hibernate.org/validator/).\n\nIf you are using the library in another environment that doesn't provide a JSR-380 implementation you will need to add the following as dependencies:\n\n```groovy\ncompile group: 'org.hibernate', name: 'hibernate-validator', version: '6.0.2.Final'\ncompile group: 'org.glassfish', name: 'javax.el', version: '3.0.1-b08'\n```\n\n## Who is using jbvext ?\n\n**Java Bean Validation Extension** was downloaded +/-450 times since October, 2017.\n\nIf you are using **jbvext** in your cool projects please send me a note so I can include you in this list.\n\n## Additional supported annotations\n\n| @Annotation | Supported Types | Description |\n| --- | --- | --- |\n| [`@After`](#after) | `Date` | Check if the Date is after the given date value, with date format as parameter. |\n| [`@Alpha`](#alpha) | `String` | Checks if the String contains only unicode letters. |\n| [`@Alphanumeric`](#alphanumeric) | `String` | Checks if the String contains unly unicode letters or digits |\n| [`@AlphanumericSpace`](#alphanumericspace) | `String` | Checks if the String contains only unicode letters, digits, empty strings or spaces. |\n| [`@AlphaSpace`](#alphaspace) | `String` | Checks if the String contains only Unicode letters and space `\" \"`. |\n| [`@AsciiPrintable`](#asciiprintable) | `String` | Checks if the String contains only ASCII printable characters. |\n| [`@Blank`](#blank) | `String` | Checks if the String is empty `\"\"`, null or whitespace(s) `\"  \"` only. |\n| [`@Before`](#before) | `Date` | Check if the Date is before the given date value, with date format as parameter. |\n| [`@CC`](#cc) | `String` | Checks if the String is a valid credit card number. |\n| [`@EndsWith`](#endswith) | `String` | Checks if the Strings ends with a specified suffix(es). |\n| [`@InstanceOf`](#instanceof) | `Object` | Check if the Object is an `instanceof` of (at least one of) the supplied value(s). |\n| [`@IPv4`](#ipv4) | `String` | Checks if the String is a valid IPv4 address. |\n| [`@IPv6`](#ipv6) | `String` | Checks if the String is a valid IPv6 address. |\n| [`@IsDate`](#isdate) | `String` | Check if the String is in a date format. |\n| [`@LowerCase`](#lowercase) | `String` | Checks if the String contains only lowercase letters. |\n| [`@MinDigits`](#mindigits) | `Double` | Checks whether the annotated value is higher than or equal to the specified minimum. |\n| [`@MaxDigits`](#maxdigits) | `Double` | Checks whether the annotated value is less than or equal to the specified maximum. |\n| [`@NotInstanceOf`](#notinstanceof) | `Object` | Check if the is not an `instanceof` of (all the) the supplied value(s). |  \n| [`@Numeric`](#numeric) | `String` | Checks if the String contains only unicode digits. *Note: A decimal point is not considered a digit and the validation fails. Use `@Parseable` instead for more advanced validations*. |\n| [`@OneOfChars`](#oneofchars) | `Character` | Checks if the Character is contained in a given array (`char[]`) of values. |\n| [`@OneOfDoubles`](#oneofdoubles) | `Double` | Check if the Double is contained in a given array (`double[]`) of values. |\n| [`@OneOfIntegers`](#oneofintegers) | `Integer` | Check if the Integer is contained in a given array (`int[]`) of values. |\n| [`@OneOfLongs`](#oneoflongs) | `Long` | Check if the Long is contained in a given array (`long[]`) of values. |\n| [`@OneOfStrings`](#oneofstrings) | `String` | Checks if the String is contained in a given array (`String[]`) of values. |\n| [`@Parseable`](#parseable) | `String` | Checks if the String can be parsed to a number (`Short`, `Integer`, `Long`, `Double`, etc.). |\n| [`@Password`](#password) | `String` | Checks if the String is a valid password. |\n| [`@StartsWith`](#startswith) | `String` | Checks if the String starts with the specified prefix(es). |\n| [`@UpperCase`](#uppercase) | `String` | Checks if the String contains only uppercase letters. |\n\n\n*Note:* \n\n*All the examples are using [project's lombok](https://projectlombok.org) annotations like `@Data`, `@NoArgsConstructor`, `@AllArgsConstructor`, etc.*\n*Those annotations are used make the examples more compact, but their use is optional.*\n\n### `@After`\n\nCheck if the Date is after the given date value. \n\nThe annotation supports a second property format that by default is \"yyyy-MM-dd'T'HH:mm:ss.SSSZ\".\n\n#### Example\n\n```java\n@Data\nclass AfterBean {\n    @After(value = \"2018-01-01\", format = \"yyyy-MM-dd\")\n    private Date isAfter = new Date(1522399999911L); // Passes // Date = 2018-03-30\n}\n```\n\n### `@Alpha`\n\nCheck if the String contains only unicode letters. \n\nBehavior:\n\n| Value | Result |\n| --- | ---\n| `null` | :x: Fails |\n| `\"\"` | :x: Fails |\n| `\" \"` | :x: Fails |\n| `\"abc\"` | :white_check_mark: Passes |\n| `\"ab2c\"` | :x: Fails |\n| `\"ab-c\"` | :x: Fails |\n\n\n### Example\n```java \n@Data\nclass TestAlpha {\n    @Alpha\n    private String alpha = \"abc\";\n\n    @Alpha /** Will fail */\n    private String nonAlpha = \"pr�s-*\";\n}\n```\n\n### `@Alphanumeric`\n\nChecks if the String contains only unicode letters or digits.\n\nBehavior:\n\n| Value | Result |\n| --- | --- |\n| `null` | :x: Fails |\n| `\"\"` | :x: Fails |\n| `\" \"` | :x: Fails |\n| `\"abc\"` | :white_check_mark: Passes |\n| `\"ab c\"` | :x: Fails |\n| `\"ab2c\"` | :white_check_mark: Passes |\n| `\"ab-c\"` | :x: Fails |\n\n### `@AlphanumericSpace`\n\nChecks if the String contains only unicode letters, digits, empty strings or spaces.\n\nBehavior:\n\n| Value | Result |\n| --- | --- |\n| `null` | :x: Fails |\n| `\"\"` | :white_check_mark: Passes |\n| `\" \"` | :white_check_mark: Passes |\n| `\"abc\"` | :white_check_mark: Passes |\n| `\"ab c\"` | :white_check_mark: Passes |\n| `\"ab2c\"` | :white_check_mark: Passes |\n| `\"ab-c\"` | :x: Fails |\n\n### `@AlphaSpace`\n\nChecks if the String contains only Unicode letters and space (\" \").\n\nBehavior:\n\n| Value | Result |\n| --- | --- |\n| `null` | :x: Fails |\n| `\"\"` | :white_check_mark: Passes |\n| `\" \"` | :white_check_mark: Passes |\n| `\"abc\"` | :white_check_mark: Passes |\n| `\"ab c\"` | :white_check_mark: Passes |\n| `\"ab1c\"` | :x: Fails |\n| `\"ab-c\"` | :x: Fails |\n \n### `@AsciiPrintable`\n \nChecks if the String is printable (ASCII printable characters).\n\nBehavior:\n\n| Value | Result |\n| --- | --- |\n| `null` | :x: Fails |\n| `\"\"` | :white_check_mark: Passes |\n| `\" \"` | :white_check_mark: Passes |\n| `\"\\u0020\"` | :white_check_mark: Passes |\n| `\"\\u007e\"` | :x: Fails |\n| `\"G\\u00fclc\\u00fc\"` | :x: Fails |\n\n\n### `@Before`\n\nCheck if the Date is before the given date value. \n\nThe annotation supports a second property format that by default is \"yyyy-MM-dd'T'HH:mm:ss.SSSZ\".\n\n#### Example\n\n```java\n@Data\nclass BeforeBean {\n    @Before(value = \"2018-12-01\", format = \"yyyy-MM-dd\")\n    private Date isBefore = new Date(1522399999911L); // Passes // Date = 2018-03-30\n}\n```\n\n### `@Blank`\n\nChecks if the String is empty `\"\"`, null or whitespace(s) `\"  \"` only.\n\nBehavior:\n\n| Value | Result |\n| --- | --- |\n| `null` | :white_check_mark: Passes |\n| `\"\"` | :white_check_mark: Passes |\n| `\" \"` | :white_check_mark: Passes |\n| `\"abc\"` | :x: Fails |\n| `\" abc \"` | :x: Fails |\n\n\n### `@CC`\n\nChecks if the String is a valid credit card number. Supported types are defined in the `CreditCardType` enum: \n\n- AMEX: \n- DINERS;\n- DISCOVER;\n- MASTERCARD;\n- VISA;\n- VPAY;\n- ALL.\n\nMultiple credit card types can be supplied to the `@CC` annotation. \n\n#### Example\n\n```java\n@Data\nclass Account {\n    @CC({ AMEX, VISA }) // AMEX or VISA\n    private String ccNumber;\n}\n```\n\nMultiple credit card types can be used.\n\n### `@EndsWith`\n\nChecks if the String `endsWith` a list of given suffix(es). If multiple suffixes are supplied, the relationship between them is `OR`(eg.: endsWith(prefix1) OR endsWith(prefix2) OR ...).\n\nThe annotation supports a second property `ignoreCase` that by default is `false`.\n\nBehavior (`ignoreCase==false`):\n\n| Value | Suffix | Result |\n| --- | --- | --- |\n| `null` | \"abc\" | :x: Fails |\n| `\"abcdef\"` | `\"def\"` | :white_check_mark: Passes |\n| `\"ABCDEF\"` | `\"def\"` | :x: Fails |\n| `\"ABCDEF\"` | `\"\"` | :white_check_mark: Passes |\n\nBehavior (`ignoreCase==true`)\n\n| Value | Suffix | Result |\n| --- | --- | --- |\n| `null` | \"abc\" | :x: Fails |\n| `\"abcdef\"` | `\"def\"` | :white_check_mark: Passes |\n| `\"ABCDEF\"` | `\"def\"` | :white_check_mark: Passes |\n| `\"ABCDEF\"` | `\"\"` | :white_check_mark: Passes |\n\n#### Example\n\n```java\n@Data\n@AllArgsConstructor\n@NoArgsConstructor\nclass SomeStrings {\n    private List\u003c@EndsWith({\"1\", \"2\"}) String\u003e someStrings;\n}\n```\n\nIn the above example we validate all the contents of `someStrings` so that they end with either `1` or `2`.\n\n### `@InstanceOf`\n\nTests if an object is instance of the supplied classes.\n\n#### Examples\n\n```java\n@Data class Animal {}\n@Data class Dog extends Animal {}\n@Data class Cat extends Animal {}\n@Data class Horse extends Animal {}\n\n@Data\n@AllArgsConstructor\nclass Pets {\n    /** This should contain only Cats and Dogs as pets, and doesn't contain null */\n    List\u003c@NotNull @InstanceOf({Dog.class, Cat.class}) Animal\u003e pets;\n}\n```\n\nIn order to test the above code we need something like this:\n\n```java\nAnimal aDog = new Dog();\nAnimal aCat = new Cat();\nPets pets = new Pets(asList(aDog, aCat));\n\nValidatorFactory factory = Validation.buildDefaultValidatorFactory();\nValidator validator = factory.getValidator();\n\nSet\u003cConstraintViolation\u003cPets\u003e\u003e validations = validator.validate(pets);\n\n// Should return 0 because the Pets class doesn't have any validation issues.\nSystem.out.println(validations.size());\n```\n\n### `@IPv4`\n\nChecks if the given string is a valid IPv4 address.\n\nThis is implemented using `InetAddressValidator.class` from [Apache Common Validator](https://commons.apache.org/proper/commons-validator/).\n\n### `@IPv6`\n\nChecks if the given string is a valid IPv6 address.\n\nThis is implemented using `InetAddressValidator.class` from [Apache Common Validator](https://commons.apache.org/proper/commons-validator/).\n\n### `@IsDate`\n\nChecks if the given string is formatted as a date.\n\n#### Example\n\n```java\n@Data\nclass IsDateBean {\n    @IsDate(\"yyyy-MM-dd\")\n    private String isDate = \"2018-12-01\"; // Passes\n}\n```\n\n### `@LowerCase`\n\nChecks if the String contains only lowercase letters.\n\nBehavior:\n\n| Value | Result |\n| --- | --- |\n| `null` | :x: Fails |\n| `\"\"` | :x: Fails |\n| `\" \"` | :x: Fails |\n| `\"abc\"` | :white_check_mark: Passes |\n| `\"abC\"` | :x: Fails |\n| `\"ab c\"` | :x: Fails |\n| `\"ab1c\"` | :x: Fails |\n| `\"ab-c\"` | :x: Fails |\n\n### `@MinDigits`\n\nChecks whether the annotated value is higher than or equal to the specified minimum.\n\n#### Example\n\n```java\n@Data\nclass MinDigitsDoubleBean {\n    @MinDigits(value = \"10.5\")\n    private Double isOk = new Double(11.0); // Passes\n\n    @MinDigits(value = \"10.5\")\n    private Double isKo = new Double(10.0); // Do not Pass\n}\n\n```\n\n#### Supported data types\n\n`Double`\n\nTODO Add support for more types\n\n\n### `@MaxDigits`\n\nChecks whether the annotated value is less than or equal to the specified maximum.\n\n#### Example\n\n```java\n@Data\nclass MaxDigitsDoubleBean {\n    @MaxDigits(value = \"10.5\")\n    private Double isKo = new Double(11.0); // Do not Pass\n\n    @MaxDigits(value = \"10.5\")\n    private Double isOk = new Double(10.0); // Passes\n}\n\n```\n\n#### Supported data types\n\n`Double`\n\nTODO Add support for more types\n\n### `@NotInstanceOf`\n\nTest if an object is not an instance of any of the supplied classes.\n\n#### Example\n\n```java\n@Data class Animal {}\n@Data class Dog extends Animal {}\n@Data class Cat extends Animal {}\n@Data class Horse extends Animal {}\n\n@Data\n@AllArgsConstructor\nclass Horses {\n    /** This should contain only horses and doesn't contain NULL */\n    List\u003c@NotNull @NotInstanceOf({Dog.class, Cat.class}) Animal\u003e horses;\n}\n```\n\n### `@Numeric`\n\nChecks if a String contains only Unicode digits. A decimal point is not an unicode digit and thus, the validation fails.\n\nBehavior:\n\n| Value | Result |\n| --- | --- |\n| `null` | :x: Fails |\n| `\"\"` | :x: Fails |\n| `\" \"` | :x: Fails |\n| `\"123\"` |  :white_check_mark: Passes | \n| `\"\\u0967\\u0968\\u0969\"` | :white_check_mark: Passes |\n| `\"12 3\"` | :x: Fails |\n| `\"12a3\"` | :x: Fails |\n| `\"12-3\"` | :x: Fails |\n\n### `@Parseable`\n\nCheck if the String can be parsed to a number. The annotations accepts the type of parsing you want to perform as an input parameter.\n\nFor example if you want to parse it `Integer`, @Parseable(TO_INT) should be used.\n\nAll the possible parsing strategies accepted are described in the enum `ParseableType`. It currently supports:\n\n- `TO_SHORT` \n- `TO_INT`\n- `TO_LONG`\n- `TO_FLOAT`\n- `TO_DOUBLE`\n\n### `@Password`\n\nCheck if a `String` is a valid password - matching a set of constraints.\n\n\n- `containsUpperCase() default true` - Needs to contain at least an Uppercase letter;\n- `boolean containsLowerCase() default true` - Needs to contain at least a Lowercase letter;\n- `boolean containsSpecialChar() default true` - Needs to contain at least one special character;\n- `boolean containsDigits() default true` - Needs to contain at least one digit;\n- `boolean allowSpace() default false` - Password can contain spaces;\n- `int minSize() default 8` - The min size of the password;\n- `int maxSize() default 32` - The maximum size of the password;\n\n### `@OneOfChars`\n\nChecks if the `Character` is contained in a given array (`char[]`) of values.\n\n#### Example\n\nIn the following example we test if the field `aOrBOrC` is either `'a'`, `'b'` or `'c'`.\n\n```java\n@Data\nclass {\n    @OneOfChars({'a', 'b', 'c'})\n    private Character aOrBOrC;\n}\n```\n\n### `@OneOfDoubles`\n\nCheck if the Double is contained in a given array (`double[]`) of values.\n\n#### Example\n\nIn the following example we test if the field `value` is either `1.0` or `2.0`.\n \n```java\n@Data\nclass {\n    @OneOfDoubles({1.0, 2.0})\n    private Double value;\n}\n```\n\n### `@OneOfIntegers`\n\nCheck if the Integer is contained in a given array (`int[]`) of values.\n\n#### Example\n\nIn the following example we test if the field `value` is either `1` or `2`.\n\n```java\n@Data\nclass {\n    @OneOfIntegers({1, 2})\n    private Integer value;\n}\n```\n\n### `@OneOfLongs`\n\nCheck if the Long is contained in a given array (`long[]`) of values.\n\n### `@OneOfStrings`\n\nChecks if the String is contained in a given array (`String[]`) of values.\n\n#### Example\n\nIn the following example we check if the value returned by the `getValue()` getter is either `\"A\"`, `\"B\"` or `\"C\"`.\n\n```java\nclass Test {\n    @OneOfStrings({ \"A\" , \"B\", \"C\"})\n    private String getValue() { return /***/ }\n}\n```\n\n### `@StartsWith`\n\nChecks if a String starts with the specified prefix(es).\n\nThe annotation supports a second property `ignoreCase` that by default is `false`.\n\nBehavior (`ignoreCase==false`):\n\n| Value | Prefix | Result |\n| --- | --- | --- |\n| `null` | \"abc\" | :x: Fails |\n| `\"abcdef\"` | `\"abc\"` | :white_check_mark: Passes |\n| `\"ABCDEF\"` | `\"abc\"` | :x: Fails |\n| `\"ABCDEF\"` | `\"\"` | :white_check_mark: Passes |\n\nBehavior (`ignoreCase==true`):\n\n| Value | Prefix | Result |\n| --- | --- | --- |\n| `null` | \"abc\" | :x: Fails |\n| `\"abcdef\"` | `\"abc\"` | :white_check_mark: Passes |\n| `\"ABCDEF\"` | `\"abc\"` | :white_check_mark: Passes |\n| `\"ABCDEF\"` | `\"\"` | :white_check_mark: Passes |\n\n\n#### Example\n\n```java\n@Data\nclass Starters {\n    private List\u003c @StartsWith(\"1\", \"2\") String\u003e starts;\n} \n```\n\n### `@UpperCase`\n\nChecks if the String contains only uppercase letters.\n\nBehavior:\n\n| Value | Result |\n| --- | --- |\n| `null` | :x: Fails |\n| `\"\"` | :x: Fails |\n| `\" \"` | :x: Fails |\n| `\"ABC\"` |  :white_check_mark: Passes |\n| `\"aBC\"` | :x: Fails |\n| `\"A C\"` | :x: Fails |\n| `\"1AB\"` | :x: Fails |\n| `\"A-C\"` | :x: Fails |\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnomemory%2Fjava-bean-validation-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnomemory%2Fjava-bean-validation-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnomemory%2Fjava-bean-validation-extension/lists"}