KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Problem Background I have a Resteasy service that uses Spring through Resteasy's SpringContextLoaderListener . This is built on Resteasy version 3.0-beta-6 . I would like to use bean validation on the incoming requests, but I can not get Resteasy to call the validator. It acts like there is no validation configured and simply passes the method the invalid input object. Question How do I enable bean validation in Resteasy? What I've Tried I have done the following: Annotated my resource class with @ValidateRequest Annotated the method parameter with @Valid Annotated the constraints on my input class. Added a dependency on resteasy-hibernatevalidator-provider Resource: @Named @Path("users") @ValidateRequest public class UserResource { /** * * @param user * * curl -x POST http://localhost:7016/api/1.0/users * */ @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) public Response createUser(@Valid User user) { //User creation logic here. } } User POJO: @JsonPropertyOrder({ "user_id", "user_name", "email" }) public class User { @JsonProperty("user_id") private Long userId; @JsonProperty("user_name") @NotNull(message = "Username must be provided") private String username; @Email(message = "Invalid email address.") private String email; //Getters and Setters Removed for Brevity } POM Entry for Validation: <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-hibernatevalidator-provider</artifactId> <version>${resteasy.version}</version> </dependency> </
Tags (comma-separated)
Save Edits
Cancel