I am validating my POJOs in a REST resource endpoint in Jersey:
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;
...
}
This seems to work fine.
However, the @Min(0)
annotation is only verified if the field inner
has the @Valid
annotation. It doesn't feel right to add the @Valid
annotation to each field which isn't a primitive.
Is there a way to tell the bean validator to automatically recursively continue the validation, even when no @Valid
annotation is present? I would like my POJO
to be as following:
public class POJO {
@NotNull
protected final String name;
@NotNull
protected final POJOInner inner;
...
}
question from:
https://stackoverflow.com/questions/27980027/jersey-jax-rs-how-to-cascade-beans-validation-recursively-with-valid-automati 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…