Hi Kohsuke,
On 4/11/06, Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_sun.com> wrote:
>
> What if you use the beforeUnmarshal hook to replace empty set by null?
Yeah that's what we're doing atm, the problem is that we then need to
be aware that the set may be null - a small thing I know, but if it is
possible to avoid it I'd like to.
cheers
dim
>
> Dmitri Colebatch wrote:
> > Hi all,
> >
> > Firstly, the area that I'm asking about JAXB is definately doing the
> > right thing, however I'd like to have the option to make it do the
> > 'wrong' thing. Let me explain.
> >
> > We have classes that have hibernate and jaxb annotations on them. We
> > have xml that looks like this:
> >
> > <foo>
> > <bars>
> > <bar> ... </bar>
> > <bar> ... </bar>
> > </bar>
> > ...
> > </foo>
> >
> > which is represented like this:
> >
> > @XmlRootElement
> > @Entity
> > class Foo
> > {
> > @XmlElementWrapper(name = "bars")
> > @Xmlelement(name = "bar")
> > Set<Bar> bars;
> > ...
> > }
> >
> > @XmlElement
> > @Entity
> > class Bar
> > {
> > ...
> > }
> >
> > When we have no bars, hibernate sets bars to be an empty set. JAXB
> > then sees an empty set (as opposed to null) and quite rightly spits
> > out this:
> >
> > <foo>
> > <bars />
> > ...
> > </foo>
> >
> > However I don't want the wrapper element if the collection is empty:
> >
> > <foo>
> > ...
> > </foo>
> >
> > I realise that what JAXB is doing is correct, but would like to ask
> > for an option:
> >
> > @XmlElementWrapper(name="bars", wrapEmptyCollection=false)
> > @XmlElement(name="bar")
> > Set<Bar> bars;
> >
> > Of course wrapEmptyCollection would default to true.
> >
> > I realise this is a corner case and we're late in the piece, but is
> > there any chance of this being considered?
>
>
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>
>
>