Ryan Delucchi
Ryan Delucchi

Reputation: 7748

XStream doesn't support custom converter cross-delegation?

It appears to me that the Java XStream library does not support cross-delegation. Am I correct in this belief?

So, I can explain what I mean, consider the following example:

<node-type-x>
  <node-type-y>
     <a/>
     <b/>
  </node-type-y>
<node-type-y>
  <c/>
  <d/>

Let's say we have a converter for "node-type-x" nodes and another converter for "node-type-y" nodes. The functionality I would like to see in XStream would be sometype of delegate() method which I could call within the node-type-x converter that would identify nested node-type-y nodes and delegate unmarshalling to the converter for such nodes and return the result so that the node-type-x converter can process the result as needed. As it stands, XStream seems to require that the converter for "node-type-x" handle processing of all children of such nodes.

Upvotes: 1

Views: 631

Answers (1)

Ryan Stewart
Ryan Stewart

Reputation: 128849

Two simple ways to do this:

  1. Register your node-type-y converter with the XStream instance, and inside your node-type-x converter, call marshallingContext.convertAnother(object).
  2. Don't register your converter with the XStream instance, and inside your node-type-x converter, call marshallingContext.convertAnother(object, converter), passing it the converter you'd like to use for the "y" that you passed it.

Upvotes: 2

Related Questions