0

Java- jersey クライアントと jersy json および xml バインディング

以下のような応答

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

マッピング クラス

@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 コード

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

次のエラーが表示されます b/c errorMessage/bRateCode/tosConfirmSummery does not exist in response b/c they are optional 次のエラーを取り除くにはどうすればよいですか。応答で利用可能な値のみを取得しても問題ありません。

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
4

1 に答える 1

2

を指定するときはpropOrder、要素に対応するすべてのマップされたフィールド/プロパティを含める必要があります。これは、値が存在するかどうかとは関係ありません。値が存在する場合、どの順序で表示されるかだけです。

例外が言うように実行し、それらを に追加する必要があります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
于 2015-03-17T10:45:20.733 に答える