0

I have a field annotated with @NotNull, when I pass JSON to my Rest resource that is missing that field, it just carries on.

From my understanding of the documentation, I don't need anything else than what I've got to do simple validation.

As far as I can tell, I have everything in place, not sure what I'm missing. Using Java 8, Jersey 2.8, maven tomcat7 plugin.

@Path("/trade")
public class TradeEndpoint {

    @Autowired
    private OrderFillService orderFillService;

    @POST
    @Path("limit")
    @Consumes({ MediaType.APPLICATION_JSON })
    public void limitOrder(@Valid LimitOrderModel limitOrder) {

        placeTrade(limitOrder);
    }
...
}

public class LimitOrderModel {

    @NotNull
    private String symbol;
    ...
}

I set the property to send errors back to the client:

public Application () {
        packages("com.foo.web.endpoint");
        register(JacksonFeature.class);
        property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, "true");
    }

I have a dependency on jersey-bean-validation:

    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-bean-validation</artifactId>
        <version>2.21</version>
    </dependency>

Posting this JSON works (placeTrade() is executed):

{
   "limitPrice":"60",
   "side":"SELL",
   "quantity":"100"
}
AfterWorkGuinness
  • 1,780
  • 4
  • 28
  • 47
  • Having the same issue, @Valid doesn't seem to throw exception at all. I checked with a custom constraint I created and it actually returns false, but no exception whatsoever. My question on SO: http://stackoverflow.com/questions/32611262/valid-not-throwing-exception/32615183 – diogocarmo Sep 17 '15 at 00:29

1 Answers1

1

Found the problem. I'm on Jersey 2.8 (makes life with jackson easier) but I was depending on jersey-bean-validation 2.21. Dropping down to jersey-bean-validation 2.8 works a treat.

AfterWorkGuinness
  • 1,780
  • 4
  • 28
  • 47