JAXB - wrong getter method?

  • From: Yoann Moranville <yoann.moranville@...>
  • To: users@...
  • Subject: JAXB - wrong getter method?
  • Date: Mon, 29 Apr 2013 16:04:47 +0200

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.


<xs:group name="m.dates">
            <xs:element name="date" type="date"/>
            <xs:element name="dateRange" type="dateRange"/>
            <xs:element name="dateSet" type="dateSet"/>
    <xs:complexType name="dateSet">
                    <xs:element name="date" type="date"/>
                    <xs:element name="dateRange" type="dateRange"/>
                <xs:choice maxOccurs="unbounded">
                    <xs:element name="date" type="date"/>
                    <xs:element name="dateRange" type="dateRange"/>


@XmlType(name = "", propOrder = {
@XmlRootElement(name = "dateSet")
public class DateSet {

    protected Date date;
    protected DateRange dateRange;
        @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:

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.


JAXB - wrong getter method?

Yoann Moranville 04/29/2013

RE: JAXB - wrong getter method?

Matthew Wise 04/30/2013
Terms of Use; Privacy Policy; Copyright ©2013-2015 (revision 20151030.c1dd42a)
Please Confirm