dev@jaxb.java.net

RE: Might need to write a custom plugin

From: Pablo Ghiglino <pablogh_2000_at_hotmail.com>
Date: Wed, 2 Sep 2015 14:32:13 +0200

Dear Mirko,

Thank you very much for your prompt response.
I have indeed tried out what you suggest. I also just tried now again to double check that I did not miss anything.
Unfortunately, the generated code is not good:
@XmlElementRef(name = "positions", type = JAXBElement.class, required = false)
protected List<Position> positions;

The problem is that I get a ClassCastException because at runtime the position list is of type JAXBElement and not of type position.

Does the @XmlElementRef annotation look correct? Or do you think that I should expect a @XmlIDREF instead?

Thanks,

Pablo.

> From: mirko_at_cm-klemm.de
> Subject: Re: Might need to write a custom plugin
> Date: Wed, 2 Sep 2015 13:55:35 +0200
> To: dev_at_jaxb.java.net
>
> Of course, instead of „AuthorBio“, you will have to enter your desired class name...
> > Am 2015-09-02 um 13:42 schrieb <pablogh_2000_at_hotmail.com> <pablogh_2000_at_hotmail.com>:
> >
> > Hi all,
> >
> > I have an schema with the following element:
> >
> > ...
> > <xsd:complexType name="AggregationNode">
> > <xsd:complexContent>
> > <xsd:extension base="avqsq:Item">
> > <xsd:sequence>
> > <xsd:maxOccurs="unbounded" minOccurs="0" name="positions"
> > type="xsd:IDREF"/>
> > </xsd:sequence>
> > ....
> > </xsd:extension>
> > </xsd:complexContent>
> > </xsd:complexType>
> > ...
> >
> > Which the jaxb code generator converts into:
> >
> > public class AggregationNode
> > ...
> > @XmlElementRef(name = "positions", type = JAXBElement.class,
> > required = false)
> > protected List<JAXBElement<Object>> positions;
> >
> > while I want this:
> >
> > public class AggregationNode
> > ..
> > @XmlIDREF
> > protected List<Position> positions;
> >
> > I haven't found a way to do this with bindings, so I thought that maybe
> > the way to go is to build a plugin.
> >
> > Before, I embark into this task, I thought it would be good check here
> > first as suggested in the main plugin development main page.
> >
> > Thanks,
> >
> > Pablo.
>