Enforce not-null field in JSON object

JAX-RS separates quite nicely the deserialization from the validation, i.e. JSON-B (or Jackson) has by design no mechanism to enforce values to be non-null, etc. Instead, you can use BeanValidation for that:

  1. Add a dependency to javax.validation:validation-api in provided scope.
  2. Add the javax.validation.constraints.NotNull annotation to your field.

For more details, go here.

Leave a Comment