We are using JAXB to generate Java classes and have encountered a few cases where generated plural method names are not correct. For example, where we expect getPhysicians
we are getting getPhysicien
. How would we customize how JAXB pluralizes specific methods?
The schema:
<xs:complexType name="physician">
<xs:sequence>
...
</xs:sequence>
</xs:complexType>
<xs:complexType name="physicianList">
<xs:sequence>
<xs:element name="Physician"
type="physician"
minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
The generated Java code:
...
public class PhysicianList {
...
@XmlElement(name = "Physician")
protected List<Physician> physicien;
...
public List<Physician> getPhysicien() {
if (physicien == null) {
physicien = new ArrayList<Physician>();
}
return this.physicien;
}
Update
This has been answered by Blaise. However, I prefer not mixing concerns such as JAXB customizations in an XML schema. So for those of you with the same preference, here is a JAXB binding file that achieves the same thing as what Blaise suggested, keeping JAXB customization out of the schema:
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<jaxb:bindings schemaLocation="myschema.xsd">
<jaxb:bindings node="//xs:complexType[@name='physicianList']//xs:element[@name='Physician']">
<jaxb:property name="physicians"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>