0

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 ?

h2066
  • 1
  • Check answer to this question https://stackoverflow.com/questions/38789307/how-to-serialize-jaxb-object-to-json-with-jaxb-reference-implementation – vmaroli Feb 04 '19 at 16:13
  • i already checked this before but no idea on how to implement my solution based on this question – h2066 Feb 04 '19 at 16:28

0 Answers0