I have some class with a terrible long name, which is transformed into XML with JAXB. Using @XmlRootElement(name="nicername")
, I am able to rename the outer XML tag to <nicername>
.
How do I rename individual attributes with ugly names of the class to some nice name too ?
You can define alternate names for your object properties using:
XMLAttribute
annotation for attributesXMLElement
annotations for elementsBoth the @XmlAttribute and @XmlElement annotations can be remapped by name using identical syntax as the @XmlRootElement annotation. So, just attach the relevant annotations to each individual field/property you need remapped and provide an argument for "name".
You can use the
@XmlAttribute
and@XmlElement
annotations to change the XML names. If you annotate the fields be sure to use the@XmlAccessorType(XmlAccessType.FIELD)
annotation on the class:Or you can annotate the properties: