0

I am generating a java class from xsd which is used in to marshal/un-marshal xml.

I have an element currently defined in my xsd as

<xs:element maxOccurs="1" minOccurs="0" name="versionLabel" type="xs:string"/>

which results in a java class containing

String versionLabel

and setters and getters, setVersionLabel()/getVersionLabel().

I want the incoming/outgoing xml element to be <version> and for that to translate to/from the java class property "versionLabel". How do I do define that behavior in the xsd?

RadamHussein
  • 891
  • 7
  • 9

1 Answers1

0

add @XmlElement annotation to the attribute and update your xsd if it used for any validation

    @XmlElement(name = "version")
    String versionLabel;
knoppix
  • 116
  • 1
  • 8
  • How would you add this to the xsd? In my case the xsd is used to generate the java class. I just don't know how to add the @XmlElement attribute to the xsd. – RadamHussein Feb 09 '21 at 13:40
  • you should update name="versionLabel" to name="version" in your xsd and add annotation to your java class – knoppix Feb 09 '21 at 17:55
  • My only issue there is that my xsd generates my java class. So I need a way to add the annotation to the xsd so that the generated java class also gets the annotation. – RadamHussein Feb 09 '21 at 19:16
  • you can use jaxb binding when you generate java class check the next post https://stackoverflow.com/questions/27039514/how-to-customize-property-name-in-jaxb – knoppix Feb 09 '21 at 22:22