如何告诉 XStream 忽略具有“class”的子元素属性
我有一些由 XStream 生成的持久 XML,看起来像:
<CalculationDefinition>
<id>47</id>
<version>3</version>
<name>RHO error (pts)</name>
<expression class="com.us.provider.expression.AbsoluteValue">
....
</expression>
</CalculationDefinition>
我现在想以不同的方式持久保留此内容,并想告诉 XStream 完全忽略表达式元素。有很多链接讨论如何使用 MapperWrapper 执行此操作(例如 XStream JIRA)但据我所知,它不适用于具有“class”属性的元素。
这可以通过在 CalculationDefinition 中保留“表达式”字段来解决,但我宁愿不必将其保留在那里,因为它没有在代码中使用。
I have some persisted XML that was generated by XStream, and looks like:
<CalculationDefinition>
<id>47</id>
<version>3</version>
<name>RHO error (pts)</name>
<expression class="com.us.provider.expression.AbsoluteValue">
....
</expression>
</CalculationDefinition>
I want to persist this content differently now, and want to tell XStream to simply ignore the expression element entirely. There's many links around that talk about how to do this with a MapperWrapper (eg XStream JIRA) but as far I can tell it doesn't work for an element that has a 'class' attribute.
This can be worked around by leaving an 'expression' field in the CalculationDefinition, but I'd rather not have to keep it there now that it's not used in code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 XSL 过滤传入的 XML 并删除表达式节点,然后再将其传递到 XStream。
You could filter the incoming XML using XSL and removing the expression nodes, before passing it to XStream.