@NotNull annotation not working as expected Java Jersey

后端 未结 2 1900
旧时难觅i
旧时难觅i 2021-01-03 00:41

I have an endpoint implementation, that I am passing an object to in the parameter list. I am trying to verify that this object is not null, using the @NotNull annotation. <

相关标签:
2条回答
  • 2021-01-03 01:12

    Not sure about the @ApiParam (from swagger?), but the following works for me with Jersey 2.22:

    @GET
    @Path("/hz-test")
    public Response proc(
                @NotNull @QueryParam("hz") String myvalue) {
    

    I suspect also that you would need to use the @NotNull with one of the other Jersey parameter annotations (e.g. @QueryParam, @HeaderParam, etc.).

    BTW, what version of jersey are you using ? (@NotNull is supported only in > 2.x AFAIK)

    0 讨论(0)
  • 2021-01-03 01:19

    If you have bean-validation dependency on classpath (org.glassfish.jersey.ext:jersey-bean-validation:2.22.2) it should be picked up by the framework and work out of the box.

    Also make sure that your @NotNull annotation comes from javax.validation.constraints package

    0 讨论(0)
提交回复
热议问题