xStream Duplicating data on retrieving from List
I'm doing a test program to write in a xml. I have 3 classes: Person, Telephone and City.
And in the Person class, I have some objects like fax, cellular of type telephone. And too Cities objects.
I have a 4th class named Persons... it is a class that have a List of type Person.
private List<Person> persons = new ArrayList<Person>();
In a main class I set the attributes and add a Person object to the list. but, when I do the follow line:
String xml = xstream.toXml(persons);
The xml appears duplicated... like this:
<persons>
<persons>
<person>
...
</person>
</persons>
</persons>
开发者_高级运维
It adds the Person object in the persons object, but it adds in a second object persons.
The necessary XML is:
<persons>
<person>
...
</person>
</persons>
Someone can help me?
And sorry for the bad English. I'm Brazilian.
Please try to give us a self-contained example. My guess is that you may need to tell XStream to make the "persons" field (with type List) "implicit". You can do this using Java method calls or annoations. See addImplicitCollection() (for example) and the XStream Annotations Tutorial.
精彩评论