I have developed in java a rest service and a soap service. The services are quite equivalent and using two different classes with the same structure but with different annotations:
-soap:
@XmlAccessorType(XmlAccessType.FIELD)
public class Car{
@XmlElement(name = "brand", required = true)
protected String brand;
}
-rest
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class Car{
@NotNull
@Size(min = 1, max = 60)
private String brand;
}
I would like to use a unique class to validate both messages (xml and json), that is why i have tried to mix annotations but without success:
@XmlAccessorType(XmlAccessType.FIELD)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class Car{
@XmlElement(name = "brand", required = true)
@NotNull
@Size(min = 1, max = 60)
protected String brand;
}
My question is what is the proper way to use a unique class to validate at the same time a rest request and a soap request ?