Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3607118
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:20:09+00:00 2026-05-18T21:20:09+00:00

We are using JAXB to generate Java classes and have encountered a few cases

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:20:09+00:00Added an answer on May 18, 2026 at 9:20 pm

    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;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Maven task to generate Java classes from an XSD file using
I am trying to generate xml using jaxb. I created xsd and generated java
Using JAXB in Java it is easy to generate from a xml schema file
What are you using for binding XML to Java? JAXB, Castor, and XMLBeans are
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I've got two Java projects, both generate Java classes based on a schema definition,
I am working on generating Java objects from an XSD file using JAXB 2.1.
I want to write an xsd for the xmlrpc spec (and generate java classes
I'm new to using JAXB, and I used JAXB 2.1.3's xjc to generate a
I have a grails project that contains a few domain objects. I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.