Try to search your question here, if you can't find : Ask Any Question Now ?

Jackson XML – Is there a Java built-in type that can be used to deserialize an object containing arrays?

HomeCategory: stackoverflowJackson XML – Is there a Java built-in type that can be used to deserialize an object containing arrays?
Avatarjohn asked 5 months ago

Let’s say my XML is :

<someObject>
  <someArray>
    <element>111</element>
    <element>222</element>
  </someArray>
</someObject>

Is there a Java built-in Type that I can use to deserialize this XML without requiring custom deserialization code?

For example, if I use a Map<Object, Object>, only one element is kept, the other one is overwritten! :

String xmlStr = "<someObject><someArray><element>111</element><element>222</element></someArray></someObject>";
Map<Object, Object> resultObj = getXmlMapper().readValue(xmlStr, new TypeReference<Map<Object, Object>>(){});
System.out.println(resultObj);

This prints :

{someArray={element=222}}

Is there any Type that Jackson understands and that can handle arrays correctly?

1 Answers
Best Answer
AvatarArben answered 5 months ago
Your Answer

18 + 12 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com