I have a problem with XStream. I have a java class called simplePerson as follows:
public class SimplePerson {
@XStreamAlias("name")
private String name;
private List<String> cars;
I am using it to convert it to json using:
XStream xstream = new XStream(new JettisonMappedXmlDriver(){
public HierarchicalStreamWriter createWriter(Writer writer) {
return new JsonWriter(writer);
}
});
xstream.setMode(XStream.NO_REFERENCES);
xstream.toXML(person)
Using it I get the following json: {"simpleperson": { "name": "joe", "cars": ["Jag", "BMW"] }}
When I use the same json to convert it back to an object using xstream.fromXML(json), I get the following exception:
Exception in thread "main" com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: Duplicate field cars
I cant figure out what is the problem. I am using the same exact json that Xstream gave as output. Any help will be appreciated.
I guess you need to add Implicit collection. like.
xstream.addImplicitCollection(SimplePerson.class, "cars");
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