Search code examples
javaxmlxstream

How to tell XStream to ignore child elements that have the 'class' attribute


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.


Solution

  • You could filter the incoming XML using XSL and removing the expression nodes, before passing it to XStream.