-
Notifications
You must be signed in to change notification settings - Fork 4
Validation (Unsupported)
Note
This page lists JSON schema validations that were considered but are currently unsupported. They might be added in a later release but there are no plans for that ATM. This page is mainly supposed to preserve the understanding of how the JSON schema concept would fit into the Java annotation based validation.
The items state for each element of an array what is expected (in terms of JSON schema constraints).
This allows very precise control over how an array should look like down to each single element in it.
When mapping JSON to a Java model it is unlikely such control is needed.
A typed language like java would model this as an object with specific properties rather than an array with specific elements.
Anyhow, if it were to be included in @Validation, we would add
Class<?>[] items() default {};Each Class<?> reference would correspond to an array and would expected to be annotated with @Validation.
This is the only way to use annotations "recursively" (for the items) by referencing an annotated type.
If items can be specified then additionalItems also seems useful to state if other items (beyond the first n elements covered by items) are allowed. In the annotation it would be:
boolean additionalItems() default YesNo.Auto; The contains constraint ensures that the array contains at least 1 element matching the conditions given as JSON schema.
Again, because annotations cannot be recursive the way to declare the @Validation is by referencing a Class that has the annotation in question.
Class<?> contains() default Void.class;If contains is added this way minContains and maxContains should also be added to allow setting a range of how often the element with the conditions should occur.
int minContains() default -1;
int maxContains() default -1;The additionalProperties that might be useful in context of JSON in Java is the variant to allow (true) or disallow (false) properties not contained in the JSON schema. ATM when mapping JSON to Java additional properties are generally ignored. Giving control to disallow it does not add much value but it would require linking validation with the Java model more tightly.
If we were to add it in @Validation it would take this form:
YesNo additionalProperties() default YesNo.Auto;