tags:

views:

638

answers:

3

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 ?

+1  A: 

I have not used XStream in some time, but implicit collections probably does what you want.

jackrabbit
He'd end up with a list of key objects, but that seems like the logical transformation to me.
Caoilte
+1  A: 

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.

krosenvold
+1  A: 

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?

Well then I'd have to do a 2 way transaformation and I suppose that makes custom serializer just as well. I'll keep it in my toolbox, though ;)
krosenvold