Let’s say I have class Example:
class Example{
String myField;
}
I want to unmarshal it in this way:
<Example>
<myField value="someValue" />
</Example>
Is it possible to unmarshal object in such way using JAXB XJC? ( I know about XmlPath in EclipseLink, but can’t use it).
You could leverage an
XmlAdapterfor this use case. In thatXmlAdapteryou will convert aStringto/from an object that has one property mapped to an XML attribute.XmlAdapter
Example
Demo
input.xml/Output
Related Example