Background problem
I have a Restaasy service that uses Spring through Resteasy SpringContextLoaderListener . It is built on Resteasy version 3.0-beta-6 .
I would like to use bean validation for incoming requests, but I cannot force Restaasy to call the validator. It acts as if verification is not configured and simply passes the method to an invalid input object.
Question
- How to enable bean check in Resteasy?
What i tried
I have done the following:
- Annotated resource class with
@ValidateRequest - Annotated method parameter using
@Valid - Annotated restrictions on my input class.
resteasy-hibernatevalidator-provider dependency added
Resource:
@Named @Path("users") @ValidateRequest public class UserResource { @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) public Response createUser(@Valid User user) {
POJO user:
@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;
POM record to check:
<dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-hibernatevalidator-provider</artifactId> <version>${resteasy.version}</version> </dependency>
The resteasy-hibernatevalidator-provider dependency contains a HibernateValidatorContextResolver and its associated HibernateValidatorAdapter .
Update (6/18/2013):
I returned the Resteasy version in my pom so that 2.3.5.Final and bean checking started working without any code changes.
gregwhitaker
source share