Search code examples
xml-serializationxstream

How can I tweek Xstream to handle XML to Java objects that include attributes and values?


For example, how would form an object from XML written like this?

<name length="4">Ryan</name>

I would normally alias a class using an annotation to "name" and then have a length and a field for the name. However, this will not work because the second field has no name.

*Edit confusing wording


Solution

  • It has been a while since I used xstream (2+ years) but I do remember using converters to change the way that objects are serialized. Check out http://x-stream.github.io/converters.html. Also this tutorial, http://x-stream.github.io/converter-tutorial.html, has some examples with attributes down towards the bottom.