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

  • SEARCH
  • Home
  • 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 5838403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:27:51+00:00 2026-05-22T11:27:51+00:00

So I want to have a list to be annotated with @XmlElements like the

  • 0

So I want to have a list to be annotated with @XmlElements like the following

@XmlElements(
        {
            @XmlElement(name = "Apple", type = Apple.class),
            @XmlElement(name = "Orange", type = Orange.class),
            @XmlElement(name = "Mango", type = Mango.class)
        }
)
public List<Fruit> getEntries() {
        return fruitList;
}

I am wondering whether there is a way to enforce the list to contain at least 1 element, because right now, the xsd looks like

<xs:complexType name="fruitList">
    <xs:sequence>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Apple" type="tns:apple"/>
        <xs:element name="Orange" type="tns:orange"/>
        <xs:element name="Mango" type="tns:mango"/>
      </xs:choice>
    </xs:sequence>
  </xs:complexType>
  • 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-22T11:27:51+00:00Added an answer on May 22, 2026 at 11:27 am

    Assuming that Apple, Orange, and Mango are subclasses of Fruit you may want to annotate the entries property with @XmlElementRef which corresponds to substitution groups in XML schema, rather than @XmlElements which corresponds to the concept of choice.

    @XmlElementRef
    public List<Fruit> getEntries() {
            return fruitList;
    }
    

    This assumes that the Apple, Orange, and Mango classes extend the Fruit class, and are annotated with @XmlRootElement

    @XmlRootElement
    public class Apple extends Fruit {
       ...
    }
    

    For More Information

    • http://bdoughan.blogspot.com/2010/11/jaxb-and-inheritance-using-substitution.html
    • http://bdoughan.blogspot.com/2010/10/jaxb-and-xsd-choice-xmlelements.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have List of particular class. I want to save this List at a
I have List List<MyType> , my type contains Age and RandomID Now I want
I have a couple of POJOs which looks like this: class Items { List<Item>
I want to have a list box in JSF. I have written a simple
I want to have my list (nav) align to the center of an image
Desired Outcome I want to have Vertical List with custom items on the left/right
I have a Dictionary<string, List<Order>> and I want to have the list of keys
I have List I want to sort Desc by Priority, which is int and
i have list of rows that user select and i want to delete them,
I have list of articles on the page in table and i want to

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.