Jersey Resource Input Method / JAX -RS bean Validation

I am using Jersey / JAX-RS through DropWizard 0.7.1 to open RESTful service endpoints. I have all my POJO entities annotated with both JAX-RS validation annotations and Hibernate / JSR-303 bean, for example:

public class Widget { @JsonProperty("fizz") @NotNull @NotEmpty private String fizz; // Can't be empty or null @JsonProperty("buzz") @Min(value=5L) private Long buzz; // Can't be less than 5 // etc. } 

When a resource method receives one of these POJOs as input (under the hood, DropWizard already deserializes the HTTP JSON object into a Widget instance), I would like to test it against Hibernate / Bean validation annotations

 @POST Response saveWidget(@PathParam("widget") Widget widget) { // Does DropWizard or Jersey have something built-in to automagically validate the // 'widget' instance? } 

Can I configure DropWizard / Jersey to validate my Widget instance, without having to write validation code here?

+6
source share
1 answer

Add @Valid to @PathParam for confirmation with Jersey.

See https://jersey.java.net/documentation/latest/bean-validation.html#d0e12201

You may need to do some configuration.

+8
source

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


All Articles