How do you customize how JAXB generates plural method names?
By default the following is generated for your schema fragment:
import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "physicianList", propOrder = { "physician" }) public class PhysicianList { @XmlElement(name = "Physician") protected List<Physician> physician; public List<Physician> getPhysician() { if (physician == null) { physician = new ArrayList<Physician>(); } return this.physician; } }
If you annotate your XML schema:
<xs:schema xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" jaxb:version="2.1"> <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:annotation> <xs:appinfo> <jaxb:property name="physicians"/> </xs:appinfo> </xs:annotation> </xs:element> </xs:sequence> </xs:complexType> </xs:schema>
Then you can generate the desired class:
import java.util.ArrayList;import java.util.List;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlType;@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name = "physicianList", propOrder = { "physicians"})public class PhysicianList { @XmlElement(name = "Physician") protected List<Physician> physicians; public List<Physician> getPhysicians() { if (physicians == null) { physicians = new ArrayList<Physician>(); } return this.physicians; }}
Maybe it's a little late to answer, but there's another way to generate plural names simply, without mixing XML Schema and JAXB Bindings.
By using JAXB XJC binding compiler with the "-extension" mode. A customization bindings file need to be added, like this one :
<?xml version="1.0"?><jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jxb:extensionBindingPrefixes="xjc"> <jxb:globalBindings> <xjc:simple/> </jxb:globalBindings></jxb:bindings>
References :