XStream doesn't support custom converter cross-delegation?

非 Y 不嫁゛ 提交于 2019-12-24 09:56:46

问题


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.


回答1:


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.


来源:https://stackoverflow.com/questions/6990468/xstream-doesnt-support-custom-converter-cross-delegation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!