问题
is there any tool to simply validate query params using Jersey (and Maven)? I'm trying to do something like this using @NotNull annotation (jersey-bean-validation):
@GET
@Path("/count")
@Produces(MediaType.APPLICATION_XML)
public Response count(@NotNull @QueryParam("my_param") String my_param) {
//TODO automatically return 400 Bad Request if my_param is null
return Response.ok("This is a response", MediaType.APPLICATION_XML).build();
}
I'd like the method to automatically validate query parameters and return 400 Bad Request if no "my_param" is provided.
回答1:
My guess is you are using Jersey 1.x, which does not support annotated validations against PathParams or QueryParams.
See Nick Telfords comments in https://groups.google.com/forum/#!topic/dropwizard-user/wb6iwrpSrSE
来源:https://stackoverflow.com/questions/21090080/jersey-validate-rest-service-parameters