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 8905789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:28:57+00:00 2026-06-15T02:28:57+00:00

My model object look something like this: @XmlRootElement(name = appConfig) @XmlType(propOrder = {}) public

  • 0

My model object look something like this:

@XmlRootElement(name = "appConfig")
@XmlType(propOrder = {})
public class Config implements Serializable {
...
private int advancedFooBar;
...
@XmlElement(name = "advancedfoobar")
public int getAdvancedFooBar() {
    return advancedFooBar;
}

public void setAdvancedFooBar(int advancedFooBar) {
    this.advancedFooBar = advancedFooBar ;
}

When I generate a schema against this class w/JXC I end up with the following for the above property:

<xs:element name="advancedfoobar" type="xs:int"/>

I’d like this to be an optional element so I tried changing

@XmlElement(name = "advancedfoobar")

to

@XmlElement(name = "advancedfoobar", required=false)

However, that did not result any change to the generated schema. What do I need to do so that the “advancedfoobar” element will be defined as optional in the generated schema?

I am using JDK 1.7.0_U3 on Windows 7 Ultimate x64.

Thanks.

-Noah

  • 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-06-15T02:28:59+00:00Added an answer on June 15, 2026 at 2:28 am

    WHAT THE JAVADOCS SAY

    According to the Javadoc for @XmlElement (see: http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElement.html#required%28%29)

    If required() is false, then the Javabean property is mapped to XML
    Schema element declaration with minOccurs=”0″. maxOccurs is “1” for a
    single valued property and “unbounded” for a multivalued property.

    The schema definition for advancedfoobar should be minOccurs=0 for the following mappings:

    @XmlElement(name = "advancedfoobar")
    public int getAdvancedFooBar() {
        return advancedFooBar;
    }
    

    and

    @XmlElement(name = "advancedfoobar", required=false)
    public int getAdvancedFooBar() {
        return advancedFooBar;
    }
    

    BUG IN MOXy AND REFERENCE IMPLEMENTATION

    There appears to be a bug in both EclipseLink JAXB (MOXy) and the JAXB reference implementation regarding primitives and optional elements. I have opened the following bug against MOXy.

    • http://bugs.eclipse.org/395301

    WORKAROUND

    You can make the property of type Integer instead of int. Or better yet just set the type property on the @XmlElement annotation to be Integer. Any type capable of holding a null value will be optional by default.

    Config

    package forum13595629;
    
    import java.io.Serializable;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement(name = "appConfig")
    @XmlType(propOrder = {})
    public class Config implements Serializable {
    
        private int advancedFooBar;
    
        @XmlElement(name = "advancedfoobar", type=Integer.class)
        public int getAdvancedFooBar() {
            return advancedFooBar;
        }
    
        public void setAdvancedFooBar(int advancedFooBar) {
            this.advancedFooBar = advancedFooBar;
        }
    
    }
    

    Demo

    package forum13595629;
    
    import java.io.IOException;
    
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.SchemaOutputResolver;
    import javax.xml.transform.Result;
    import javax.xml.transform.stream.StreamResult;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Config.class);
    
            jc.generateSchema(new SchemaOutputResolver() {
    
                @Override
                public Result createOutput(String namespaceUri,
                        String suggestedFileName) throws IOException {
                    StreamResult result = new StreamResult(System.out);
                    result.setSystemId(suggestedFileName);
                    return result;
                }
    
            });
    
        }
    
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <xsd:complexType name="config">
          <xsd:all>
             <xsd:element name="advancedfoobar" type="xsd:int" minOccurs="0"/>
          </xsd:all>
       </xsd:complexType>
       <xsd:element name="appConfig" type="config"/>
    </xsd:schema>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django model that looks something like this: class Person(models.Model): name =
I would like to always have my model look to see if an object
i created a model object in PHP class User { public $title; public function
I have some domain classes that look something like this, that I want to
I'm working on some Django-code that has a model like this: class Status(models.Model): code
I have 2 tables namely subscriber and contact. Tables look something like this: subscriber
You can validate a model object with EF 5 Code-First like that: var validationResult
Say I have a model object 'Person' defined, which has a field called 'Name'.
I'd like to load collections of repeated objects. My model looks like this: Item
My data model is simple: class Neighborhood(models.Model): name = models.CharField(max_length = 50) slug =

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.