0

I have a schema where element names are defined in PascalCase eg:

<xsd:element name="EmployeeName" minOccurs="0" maxOccurs="1">

But I would like this to generate as:

@XmlElement(name = "employeeName")

I know this sounds slightly strange but it will then allow me to use Jackson JAXB annotation support to have my JSON generated in camelCase.

Is this possible?

MandyW
  • 1,117
  • 3
  • 14
  • 23

1 Answers1

0

Yes, it is possible to change the XML element name to (nearly) whatever you want by way of the annotation directives.

In this example, "price" is renamed to "itemprice". Java is not case insensitive, so your camel casing will be honored.

 //Example: Code fragment
 public class USPrice {
     @XmlElement(name="itemprice")
     public java.math.BigDecimal price;
 }

 <!-- Example: Local XML Schema element -->
 <xs:complexType name="USPrice"/>
   <xs:sequence>
     <xs:element name="itemprice" type="xs:decimal" minOccurs="0"/>
   </sequence>
 </xs:complexType>

This example comes from the JAXB javadocs.

Note that JAXB support has a few "how to use it" workflows, "XSD to generate supporting Java classes", and "Java classes to generate an XSD". I prefer the latter, but you may be using the former. If you are, then you need to alter your XSD to have camelCase element names there.

There is no "use my XSD to generate Java classes, but with some overrides" workflow. Perhaps that's where the confusion comes from. Likewise, there is no "Use Java class annotations to generated XSD documents, but with some overrides". What you specify is going to be what you get, name-wise.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • Thanks very much Edwin, this confirms to me there is no easy way to do what I want via any sort of binding. That's fine I will look at alternatives like changing the XSD as you suggest (or maybe I'll move to JSON schema!). – MandyW Mar 18 '16 at 21:27