Image I have an element like this <someElement a="" b="" number="1" scale="meters"><child/></someElement>
scale and number always appear together but they are not defined in one exclusive element.
When unmarshalling the someElement element to a SomeElement java instance I want a single member in the SomeElement class to represent number and scale.
At the moment both number and scale are attributes and then the afterUnmarshall() method is used for calculating one number.
Is there a way to do this without having the two member fields size and scale? Maybe with a XmlAdapter? How would I use this in this case?
Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.
MOXy offers the
@XmlTransformationextension that allows you to represent a Java field/property as several XML nodes.For More Information
UPDATE
Alternatively you could use an
XmlAdapterfor this use case. The adapter will we responsible for converting the single type representing number and scale (represented as FOO below) to a type with separate properties for number and scale. You will still need to use the MOXy implementation to leverage the@XmlPathextension:For More Information