java - jackson xml lists deserialization recognized as duplicate keys -


i'm trying convert xml json using jackson-2.5.1 , jackson-dataformat-xml-2.5.1
xml structure received web server , unknown, therefore can't have java class represent object, , i'm trying convert directly treenode using objectmapper.readtree.
problem jackson failing parse lists. takes last item of list.
code:

string xml = "<root><name>john</name><list><item>val1</item>val2<item>val3</item></list></root>"; xmlmapper xmlmapper = new xmlmapper(); jsonnode jsonresult = xmlmapper.readtree(xml); 

the json result:

{"name":"john","list":{"item":"val3"}}   

if enable failure on duplicate keys xmlmapper.enable(deserializationfeature.fail_on_reading_dup_tree_key), exception thrown:
com.fasterxml.jackson.databind.jsonmappingexception: duplicate field 'item' objectnode: not allowed when fail_on_reading_dup_tree_key enabled

is there feature fixes problem? there way me write custom deserializer in event of duplicate keys turn them array?

you can catch exception , :

list<myclass> myobjects = mapper.readvalue(input, new typereference<list<myclass>>(){}); 

(got here how use jackson deserialise array of objects)

it's hackish approach , have figure out how resume there.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -