Thanks for your response, Blaise. The problem seems to be due to the fact that I'm trying to generate xsd:all by specifying propOrder = {}. With that annotation MOXy doesn't generate the minOccurs="0". I've modified your demo class to demonstrate the issue:
package moxy.test;
import java.io.IOException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.bind.annotation.XmlType;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.persistence.Version;
public class Test {
@XmlType(propOrder = {})
public static class Root {
private Integer duration;
private Integer period;
public Integer getPeriod() {
return this.period;
}
public void setPeriod(Integer period) {
this.period = period;
}
public Integer getDuration() {
return duration;
}
public void setDuration(Integer duration) {
this.duration = duration;
}
}
public static class MySchemaOutputResolver extends SchemaOutputResolver {
@Override
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
StreamResult result = new StreamResult(System.out);
result.setSystemId(suggestedFileName);
return result;
}
}
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class);
System.out.println(jc);
System.out.println(Version.getVersionString());
jc.generateSchema(new MySchemaOutputResolver());
}
}
The following is produced with MOXy. Notice there is no minOccurs attribute:
2.1.2.v20101206-r8635
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="root">
<xsd:all>
<xsd:element name="duration" type="xsd:int"/>
<xsd:element name="period" type="xsd:int"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
If you remove the @XmlType(propOrder = {}) annotation the generated schema has the minOccurs present but with the elements as a sequence:
org.eclipse.persistence.jaxb.JAXBContext@cdedfd
2.1.2.v20101206-r8635
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="root">
<xsd:sequence>
<xsd:element name="duration" type="xsd:int" minOccurs="0"/>
<xsd:element name="period" type="xsd:int" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
And just for reference, here is what is generated by Sun's JAXB reference implementation:
jar:file:/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/rt.jar!/com/sun/xml/internal/bind/v2/runtime/JAXBContextImpl.class Build-Id: 1.6.0_21
...
2.1.2.v20101206-r8635
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="root">
<xs:all>
<xs:element name="duration" type="xs:int" minOccurs="0"/>
<xs:element name="period" type="xs:int" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:schema>
Thanks in advance!