Java / jersey / jackson - JSON input confirmation

I am writing a REST API with a Java / Jersey / Jackson stack. All JSON parsing and generation is done using Jackson. REST level handled by jersey. It will be built into the Grizzly container.

In my API, I accept JSON at my endpoints. For instance:

@POST
public Response post(final SomeObject input) {
    return ...;
}

What is the best way to check input? There are some things that I would like to confirm:

  • input must not be null
  • certain fields inputmust not be empty
  • certain fields inputmust follow regular expression (text fields)
  • certain fields inputmust be in a range (numeric fields)
  • ...

, . , , .

+4
2

BeanValidationApi (javax.validation.constraints), @NotNull,@Pattern .. Bean

+2

JSON Schema.

Jackson, , .

However, this means that you will need to change your logic to get JSON (how JsonNode) instead of serialized POJO and only then serialize it to POJO.

+4
source

Source: https://habr.com/ru/post/1570832/


All Articles