Your dateSet element doesn't compile.
"com.sun.istack.SAXParseException2: Element "date" shows up in more than one properties."
minOccurs="1" is the default so what you have for your dateSet is effectively:
<xsd:complexType name="dateSet">
<xsd:sequence>
<xsd:choice minOccurs="2" maxOccurs="unbounded">
<xsd:element name="date" type="xsd:date"/>
<xsd:element name="dateRange" type="dateRange"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
Don't know if this helps you.
-----Original Message-----
From: Yoann Moranville [mailto:yoann.moranville_at_gmail.com]
Sent: 29 April 2013 15:05
To: users_at_jaxb.java.net
Subject: JAXB - wrong getter method?
Hello all,
I have a problem using JAXB (com.sun.xml.bind - jaxb-impl - 2.2.6), so I must either be doing something wrong or there is a bug somewhere. I hope I can get some help from you.
I have an XML schema which I used to create the object classes, I will add the corresponding code in the mail.
The problem seems to be that I am loosing data on the way.
XSD:
<xs:group name="m.dates">
<xs:choice>
<xs:element name="date" type="date"/>
<xs:element name="dateRange" type="dateRange"/>
<xs:element name="dateSet" type="dateSet"/>
</xs:choice>
</xs:group>
<xs:complexType name="dateSet">
<xs:sequence>
<xs:choice>
<xs:element name="date" type="date"/>
<xs:element name="dateRange" type="dateRange"/>
</xs:choice>
<xs:choice maxOccurs="unbounded">
<xs:element name="date" type="date"/>
<xs:element name="dateRange" type="dateRange"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
Object:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"date",
"dateRange",
"dateOrDateRange"
})
@XmlRootElement(name = "dateSet")
public class DateSet {
protected Date date;
protected DateRange dateRange;
@XmlElements({
@XmlElement(name = "date", type = Date.class),
@XmlElement(name = "dateRange", type = DateRange.class)
})
protected List<Object> dateOrDateRange;
public Date getDate() {
return date;
}
public void setDate(Date value) {
this.date = value;
}
public DateRange getDateRange() {
return dateRange;
}
public void setDateRange(DateRange value) {
this.dateRange = value;
}
public List<Object> getDateOrDateRange() {
if (dateOrDateRange == null) {
dateOrDateRange = new ArrayList<Object>();
}
return this.dateOrDateRange;
}
}
Unfortunately, when using opening an XML file containing this part:
<dateSet>
<date>2000</date>
<date>2001</date>
<dateRange> <fromDate>2002</fromDate>
<toDate>2011</toDate>
</dateRange>
</dateSet>
Then I loose the first date element. So all the rest gets send to DateSet/Date and DateSet/DateRange but not the first one. I would have expected to retrieve the data via the List<Object> getDateOrDateRange() method since I have more than one "date" element but it does not seem to be the case.
Anyone has any idea of what I am doing wrong? If you need more code or explanation, please let me know.
Cheers,
Yoann
--
LEGAL NOTICE
This message is intended for the use of the named recipient(s) only and may contain
confidential and / or privileged information. If you are not the intended recipient, please
contact the sender and delete this message. Any unauthorised use of the information
contained in this message is prohibited.
Mango Business Solutions Limited is registered in England under No. 4560258 with its
registered office at Suite 3, Middlesex House, Rutherford Close, Stevenage, Herts, SG1 2EF,
UK.
PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS EMAIL