Reputation: 15799
My question is similar to Resteasy Bean Validation Not Being Invoked. The solutions there don't work, though.
I'm using Resteasy 3.0.9.Final with resteasy-validator-provider-11 in my pom. I'm launching the whole thing using a custom Jetty class.
Weirdly, validation is working fine on @PathParams, but not on beans.
@POST
@Path("/foo/{myParam}")
public Message post(MyBean myBean, @PathParam("myParam") @Size(min=5) String myParam) {
return new Message("bean:" + myBean.toString());
}
public static class MyBean {
@NotNull
public String myStr;
@Max(value = 3)
public int myInt;
public String toString() {
return myStr + myInt;
}
}
In this case, the @Size constraint on myParam is working fine. But the @NotNull and @Max constraints in MyBean are not getting invoked.
Am I missing an annotation somewhere?
Here's one more clue. My logs include these entries:
2014-12-30 12:16:56 org.hibernate.validator.internal.util.Version 6446 INFO HV000001: Hibernate Validator 5.0.1.Final
2014-12-30 12:16:56 org.jboss.resteasy.plugins.validation.AbstractValidatorContextResolver 6477 INFO Unable to find CDI supporting ValidatorFactory. Using default ValidatorFactory
Upvotes: 1
Views: 1514
Reputation: 11723
I believe, but not 100% sure, that the issue is that you're missing @Valid
on the MyBean
parameter. I would also recommend to make it a separate class, rather than a static class.
Per the spec, validation constraints on methods where the object is a complex object need to have the parameter annotated @Valid
to ensure that the constraints are cascaded.
Upvotes: 2