Reputation: 17589
I got this from the JAXB doc for @XmlElement
If required() is true, then Javabean property is mapped to an XML schema element declaration with minOccurs="1". maxOccurs is "1" for a single valued property and "unbounded" for a multivalued property.
However when I say
@XmlElement(name = "Name", required = true, nillable = false)
I get the following in the .xsd
<xs:element name="Name" type="xs:string"/>
I wonder how I can make minOccurs to equal to 1. It seems like required = true
causes minOccurs
to disappear
Edit I realize that the default value is 1. Is there anyway to for minOccurs to show up as 1 in the .xsd
Edit2 I am using JAXBContext.generateSchema to generate the schema (FYI)
Upvotes: 2
Views: 5321
Reputation: 148977
The JAXB spec defines the behaviour:
If required() is true, then Javabean property is mapped to an XML schema element declaration with minOccurs="1". maxOccurs is "1" for a single valued property and "unbounded" for a multivalued property.
The indivual implementations (Metro, EclipseLink MOXy, Apache JaxMe) are free to generate the XML schema as they see fit according to this rule. Metro and MOXy (I'm the tech lead) choose to use the absence of the minOccurs attribute to indicate minOccurs="1".
Upvotes: 2
Reputation: 4537
The default for xs:element is minOccurs=1. So its possible to omit the attribute and still have the same meaning, which might be what jaxb is doing.
EDIT: Saw your edit too late. I've never seen a way to do this, but that doesn't mean its not possible.
Upvotes: 0
Reputation: 17
I'm no JAXB expert, but I believe that "minOccurs" is, by default, set to 1 with an xs:element tag. In other words, if the "minOccurs" attribute is missing from the tag, its default is 1.
Edit: Sorry, didn't see your edit until it was too late!
Upvotes: 1