【发布时间】:2023-03-23 02:15:02
【问题描述】:
我正在泽西岛的 REST 资源端点中验证我的 POJO:
public class Resource {
@POST
public Response post(@NotNull @Valid final POJO pojo) {
...
}
}
public class POJO {
@NotNull
protected final String name;
@NotNull
@Valid
protected final POJOInner inner;
...
}
public class POJOInner {
@Min(0)
protected final int limit;
...
}
这似乎工作正常。
但是,只有当字段 inner 具有 @Valid 注释时,才会验证 @Min(0) 注释。将@Valid 注解添加到每个不是原语的字段感觉不对。
有没有办法告诉 bean 验证器自动递归地继续验证,即使没有 @Valid 注释存在?我希望我的POJO 如下:
public class POJO {
@NotNull
protected final String name;
@NotNull
protected final POJOInner inner;
...
}
【问题讨论】:
-
你使用的是什么 bean 验证运行时?
-
我正在使用 Hibernate 验证器。
标签: java jersey jax-rs bean-validation