I have an incoming xml from Recurly service with list of transactions. Sometimes it's empty and looks like this:
<transactions type="array">
</transactions>
I need to deserialize this using Jackson. I've tried next mapping
@XmlRootElement(name = "transactions")
public class TransactionObjectListResponse extends ArrayList<TransactionObjectResponse> {
}
where TransactionObjectResponse class for each transaction. It works fine for non-empty collections, but fails when no transactions came. Next message appears:
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)
I used XmlMapper directly,
xmlMapper.readValue(responseXml, TransactionObjectListResponse.class);
Response entity structure isn't strict, any help would be appricated. Thanks.