Deserializing a legacy XML structure in xstream
Question
I'm trying to deserialize an xml structure that looks like this:
<somecontainer>
<key1>Value1</key1>
<key1>Value2</key1>
<key2>Value3</key2>
<key2>Value4</key2>
</somecontainer>
I can basically choose what kind if element to deserialize to, maybe something like a List of Pair or something. The essence here is that the element names are the keys.
And no, I cannot change the xml structure. Anyone know how to do this with xstream ?
Solution
I have found that a custom serializer is needed for this case, no way around it.
Similarly
<node attr1="xxx">value1</node>
also needs a custom serializer.
OTHER TIPS
You might also consider doing an XSL transformation of the document to a normalized form before deserializing it. That would obviate the need for a custom serializer.
I guess the trade off is if it is easier to maintain a custom serializer or an XSL transformation step?
I have not used XStream in some time, but implicit collections probably does what you want.