javax.validation 被球衣忽略
我正在尝试使用 Jersey 从用户获取 JSON 请求来创建供应商
@POST
@Produces({APPLICATION_JSON})
@Consumes({APPLICATION_JSON})
@Path("create")
public Response create(VendorTO vendorTO) throws Exception {
,但在它转换为供应商对象之前,我想使用 javax.validation 对其进行验证,
我在我的 pojo 中添加了约束,如下所示
{@JsonSerialize(include=Inclusion.NON_NULL)
public class VendorTO {
@NotNull
private Integer userId;
@Size(min = 2)
private String vendorName;
private String address1;
private String address2;
private String city;
private String state;
private String country;
private String email;
private String phone;
}
但它似乎不起作用。有人可以帮忙吗?
I am trying to use Jersey to get JSON request from the user to create vendor
@POST
@Produces({APPLICATION_JSON})
@Consumes({APPLICATION_JSON})
@Path("create")
public Response create(VendorTO vendorTO) throws Exception {
But before it converts in vendorTO object I want to validate it with javax.validation
I have added constraints in my pojo like this
{@JsonSerialize(include=Inclusion.NON_NULL)
public class VendorTO {
@NotNull
private Integer userId;
@Size(min = 2)
private String vendorName;
private String address1;
private String address2;
private String city;
private String state;
private String country;
private String email;
private String phone;
}
but it doesnt seems to be working. Can anyone help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要告诉框架该参数应该是
@已验证:
You need to tell the framework that the parameter should be
@Valid
ated:目前,Jersey 似乎不支持原生 JSR 303。您可能必须编写一些 ResourceFilter 并手动处理验证。
At this point, it appears Jersey does not support JSR 303 natively. You might have to write some ResourceFilters and handle the validation manually.