There is a lot information at stackoverflow about how to deserialize a json array using Gson.
But how can I do the same using XStream with jettison?
Here is json:
{"entity":[{"id":"1", "name":"aaa"}, {"id":"2", "name":"bbb"}]}
Here is XStream code how I try to parse it:
XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.alias("entity", Entity[].class);
return (Entity[])xstream.fromXML(jsonString);
I have following exception:
com.thoughtworks.xstream.converters.ConversionException: id : id
As can be seen from this answer related to root element XStream fails when there is not root element in JSON.
Once you map entity to certain Java class XStream cannot find root element for pairs of id and name (as in JSON they are not enclosed in element).
Only hand-made wrapper, manipulating input streams or using custom converter can help here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With