3
我有一個來自Recurly服務的傳入xml和事務列表。有時它是空的,看起來像這樣:Jackson空xml數組反序列化
<transactions type="array">
</transactions>
我需要反序列化使用傑克遜。我已經嘗試了下一個映射
@XmlRootElement(name = "transactions")
public class TransactionObjectListResponse extends ArrayList<TransactionObjectResponse> {
}
其中TransactionObjectResponse類用於每個事務。它適用於非空集合,但在沒有事務發生時會失敗。出現一條消息:
java.lang.IllegalStateException: Missing name, in state: END_ARRAY
at com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.getCurrentName(FromXmlParser.java:310)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:289)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:157)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:123)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:230)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:207)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
我直接使用XmlMapper,
xmlMapper.readValue(responseXml, TransactionObjectListResponse.class);
響應實體結構不嚴格,任何幫助,將appricated。謝謝。
不幸的是,它不工作:( –