@NotNull标注未按预期运行的Java泽西 [英] @NotNull annotation not working as expected Java Jersey

查看:738
本文介绍了@NotNull标注未按预期运行的Java泽西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个端点实现,那我传递一个对象的参数列表。我试图验证此对象不为空,使用@NotNull注解。

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.

@POST 
@Path("path") 
public Response endpointMethod(@NotNull @ApiParam(value = "abc", required = true) Object object) { 
        return Response.status(Status.OK).build(); 
} 

如果该对象被证实是不为空,则端点将只返回一个200 OK响应。
然而,当我火到这个端点的请求,使用指定的路径,并没有在身体里,有没有被引发的错误。相反,我能够检索200响应(甚至当我检查,如果该对象返回之前是空的反应,这表明是这样)。

If the object is verified to be not null, then the endpoint will just return a 200 OK response. However, when I fire a request to this endpoint, with the specified path, and nothing in the body, there are no errors that are thrown. Instead, I am able to retrieve the 200 response (even when I check if the object is null before return the response, it shows that that is the case).

有人能指导我如何验证对象是否以正确的方式空?

Can someone guide me on how to verify whether the object is null in the correct way?

推荐答案

如果您有关于classpath中豆验证的依赖(org.glassfish.jersey.ext:球衣豆验证:2.22.2)应该拿起由框架和工作的开箱。

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.

另外,还要确保你的@NotNull注释来自javax.validation.constraints包

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

这篇关于@NotNull标注未按预期运行的Java泽西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆