0

Java- jersey client and jersy json and xml binding

response as following

{"corp":"01105","rateCodeOffers":[{"rateCode":"!I","tosOffers":["MH0000010005"]}]}

mapping class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
 "corp",
 "rateCodeOffers"
})
@XmlRootElement(name = "corpRateCodeTosOffers")
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
    public class CorpRcTosOffer implements Serializable {

    @XmlElement(required = true)
    private String corp;

    @XmlElement(required = true)
    private String errorMessage;

    @XmlElement(required = true)
    private String bRateCode;

    @XmlElement(required = true)
    private List<RatecodeTosOffers> rateCodeOffers;

    @XmlElement(required = false)
    private Map<String, List<TosConfirmSummary>> tosConfirmSummery;

    ... getter and setters
  }

Java code to call

ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, payload);
 response.getEntity(CorpRcTosOffer.class);

I am getting following error b/c errorMessage/bRateCode/tosConfirmSummery does not exist in response b/c they are optional what should i do to get rid of the following error. i am ok with to get only those values which are available in response.

javax.ws.rs.WebApplicationException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 5 counts of IllegalAnnotationExceptions
Property errorMessage is present but not specified in @XmlType.propOrder
    this problem is related to the following location:
        at private java.lang.String com.abc.app.CorpRcTosOffer.errorMessage
        at com.abc.app.CorpRcTosOffer
Property bRateCode is present but not specified in @XmlType.propOrder
    this problem is related to the following location:
        at private java.lang.String com.abc.app.CorpRcTosOffer.bRateCode
        at com.abc.app.CorpRcTosOffer
Property tosConfirmSummery is present but not specified in @XmlType.propOrder
    this problem is related to the following location:
        at private java.util.Map com.abc.app.CorpRcTosOffer.tosConfirmSummery
        at com.abc.app.CorpRcTosOffer
java.util.Map is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at java.util.Map
        at private java.util.Map com.abc.app.CorpRcTosOffer.tosConfirmSummery
        at com.abc.app.CorpRcTosOffer
java.util.Map does not have a no-arg default constructor.
    this problem is related to the following location:
        at java.util.Map
        at private java.util.Map com.abc.app.CorpRcTosOffer.tosConfirmSummery
        at com.abc.app.CorpRcTosOffer
d-man
  • 57,473
  • 85
  • 212
  • 296

1 Answers1

2

When you specify a propOrder you need to include all mapped fields/properties that correspond to an element in it. This has nothing to do with the value being present or not, just that if the value was present what order would it appear in.

You need to do as the exception says and add them to the propOrder.

Property bRateCode is present but not specified in @XmlType.propOrder
    this problem is related to the following location:
        at private java.lang.String com.abc.app.CorpRcTosOffer.bRateCode
        at com.abc.app.CorpRcTosOffer
bdoughan
  • 147,609
  • 23
  • 300
  • 400