I have the below Pojo which I need to validate. All the below fields are mandatory but they can have null values.I can use @JsonCreator to make fields required but sonar rules complaining since i have many fields.Is there any other elegant way to solve this problem? I am using Spring Boot ,Jackson and Java 8. @Valid public class Bar {
@Length(min = 1, max = 2)
private String bid;
@JsonProperty(value="bname")
private String bname;
//i have 10 more fields omitted for brevity
This should be the only valid json
"bar":{"bid":"1","bname":"w"}
But currently i am able to process this invalid Json too which is incorrect
"bar":{"bid":"1"}