users@jaxb.java.net

Collections: Setters Required?

From: Mark Emeny <Mark.Emeny_at_focus-solutions.co.uk>
Date: Tue, 28 Nov 2006 10:12:49 -0000

Hi,


 

I have several classes where I have added @XmlType annotations and have
elected to annotate properties (that is, getters).

 

Within these classes I have numerous collections that I have represented
as Sets. As per the specification, I have not provided setters for these
collections. When marshalling an object hierarchy all looks good (the
XML is what I would expect, with nested levels of objects)...

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<Case>

    <Quote>

        <Benefit>

            <Test>123</Test>

        </Benefit>

        <Document>

            <Test>123</Test>

        </Document>

        <Document>

            <Test>456</Test>

        </Document>

    </Quote>

    <Quote>

        <Benefit>

            <Test>123</Test>

        </Benefit>

        <Document>

            <Test>123</Test>

        </Document>

        <Document>

            <Test>456</Test>

        </Document>

    </Quote>

</Case>

 

However, when I unmarshal the XML I find that not all elements have been
mapped to Java objects.

 

I have added a Listener to the unmarshaller and followed the process via
the "afterUnmarshal" method (all looks good and I can see each object
being unmarshalled) but the resultant object hierarchy has missing items
within some collections (for example, I can only see one "Quote" for the
"Case").

 

I have also added a ValidationEventHandler and can actually see JAXB
reporting that a setter could not be found, but was not needed if the
getter returned a collection (which of course it did). The only way I
could solve this was to add setters for the collections or annotate
fields rather than properties.

 

Have I missed something in the specification or is this in fact a bug?

 

Regards,

 

Mark.