Add the @Present constraint for JsonNullable
Adds @Present for #176: the JsonNullable must be set, so an undefined one is invalid and an explicit null is valid. It comes for jakarta.validation and javax.validation under the same name in two packages, and needs payload = Unwrapping.Skip.class where it is used, because the value extractor unwraps by default. The README says what happens without it.
@jpfinne the template's packages are org.openapitools.jackson.nullable.jakarta and .javax.
Closes #176
Summary by cubic
Adds a @Present constraint for JsonNullable that requires the property to be set: JsonNullable.undefined() and a null reference are invalid, while an explicit null (JsonNullable.of(null)) is valid. This is the opposite of @NotNull on a JsonNullable. Closes #176.
The annotation ships in both org.openapitools.jackson.nullable.jakarta and org.openapitools.jackson.nullable.javax, which are now exported in the module-info files. It supports fields, getters, constructor parameters, groups, and repetition, with a default message of "must be present".
Usage
- Use
@Present(payload = Unwrapping.Skip.class)at the use site. The module's value extractor unwrapsJsonNullableby default, so without the payload an undefined property passes unchecked and a defined value throwsUnexpectedTypeException. - In composed constraints the payload is ignored as a meta-annotation, so give it where the composed annotation is used.