0

Because of legacy (unfortunate) reasons, we have the same xml roots for 2 different representations. With xstream, how would we let unmarshaller to use a class we need while unmarshalling.

I am thinking of passing some context (through ThreadContext) so that xstream would use that information to pick the right class during unmarshalling, though I am not sure where to start. Any suggestions are very appreciated.

Notes:

  • Root tags are same for both XML
  • No other information (attribute) on root tag is available to distingish 2 representations
  • Cannot change the xml because of legacy reasons

Ideally I would like the solution to work with Spring-OXM but will take shortcuts if needed

Stackee007
  • 3,196
  • 1
  • 26
  • 39

1 Answers1

0

You know in advance which of the two representations you are about to parse.

So you can create two instances of the xStream in the beginning, and configure the converters and aliases differently for each of them, and use one instance per representation.

This approach seems to me cleaner and more controllable than setting a global context variable and then having a bunch of ifs inside the converters, and dealing with potential ambiguities.

Jan X Marek
  • 2,464
  • 2
  • 18
  • 26