users@jaxb.java.net

Re: wrapping collections by using adapters

From: Sekhar Vajjhala <Sekhar.Vajjhala_at_Sun.COM>
Date: Fri, 17 Mar 2006 08:53:28 -0500

Dmitri Colebatch wrote:

>Hi all,
>
>I have a problem trying to map a collection. I've had this for a
>while and have been putting it aside but am hoping that someone might
>be able to point out something obvious. I'll attach some runnable
>code, but will paste some of it here for clarity.
>
>I have an object Foo, that has a set of Bar instances. I want this to
>map to the following xml:
>
><foo>
> <bars>
> <bar>
> <name>abc</name>
> <price>123</price>
> </bar>
> </bars>
></foo>
>
>I've tried doing this by having a "BarWrapper" class that I inject
>using an adapter, however this isn't working (CCE on marshall). I've
>tried various other workarounds as well, but none of them seem to get
>me to where I want. It seems like a simple problem, I feel like I
>must be missing something obvious. Any suggestions?
>
Use @XmlElementWrapper annotation and redesign Foo.java slightly. See
javadoc
https://jaxb.dev.java.net/nonav/jaxb20-pfd/api/javax/xml/bind/annotation/XmlElementWrapper.html

@XmlAccessorType(FIELD)
@XmlRootElement
public class Foo
{
    @XmlElementWrapper(name="bars")
    Set<Bar> bar;
}

Sekhar

>
>The reason I don't just change the xml structure is that I am also
>mapping this class with hibernate annotaions, and I don't see a way to
>remove the middle man (BarWrapper) when doing a one-to-many.
>
>cheers
>dim
>
>(code attached)
>
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>