在反序列化对Java对象的XML响应时遇到了问题。 XML响应字符串:
<DROPFEE v="some text5" vType="1"/>
<Coverages>
<Charge Amount="4.10" Code="001" Currency="EUR" Descr="Some Text" ID="229.470" PaidLocally="Y" TaxInclusive="Y"/>
<Charge Code="002" Descr="Text here" ID="225.674">
<Restrictions>
<Restriction Text="Call for details" Type="Call"/>
</Restrictions>
</Charge>
</Coverages>
<Fees>
<Charge Code="2" Descr="Drop" ID="2">
<Restrictions>
<Restriction Text="some text here" Type="Text"/>
</Restrictions>
</Charge>
</Fees>
POJO类别:
@JacksonXmlProperty(localName="DROPFEE")
private RequoteDropFeeResponse dropfee;
@JacksonXmlElementWrapper(localName="Coverages")
@JacksonXmlProperty(localName="Charge")
private List<RequoteChargeResponse> coverages;
@JacksonXmlElementWrapper(localName="Fees")
@JacksonXmlProperty(localName="Charge")
private List<RequoteChargeResponse> feeCharges;
public List<RequoteChargeResponse> getCoverages() {
return coverages;
}
public void setCoverages(List<RequoteChargeResponse> coverages) {
this.coverages = coverages;
}
public List<RequoteChargeResponse> getFeeCharges() {
return feeCharges;
}
public void setFeeCharges(List<RequoteChargeResponse> feeCharges) {
this.feeCharges = feeCharges;
}
转换方法:
public static Object convertXMLStringToJavaObject(String xmlString, Class<?> cls)
throws JsonParseException, JsonMappingException, IOException{
XmlMapper xmlMapper = new XmlMapper();
Object object = xmlMapper.readValue(xmlString, cls);
return object;
}
因此,这里它引发异常com.fasterxml.jackson.databind.JsonMappingException:多个表示属性“ Charge”的字段:com.service.server.model.integration.RequoteReferenceResponse#coverages与com.service.server.model.integration。 RequoteReferenceResponse#feeCharges 在[来源:java.io.StringReader@179ecd0c;行:1,列:39]