users@jaxb.java.net

RE: How to marshall values as elements?

From: Markus Karg <markus.karg_at_gmx.net>
Date: Thu, 5 May 2011 18:13:17 +0200

Yes, just noticed JAXBElement some minutes ago. Thanks, anyways, for this
solution! :-)

> -----Original Message-----
> From: aleksei.valikov_at_gmail.com [mailto:aleksei.valikov_at_gmail.com] On
> Behalf Of Aleksei Valikov
> Sent: Donnerstag, 5. Mai 2011 14:53
> To: users_at_jaxb.java.net
> Subject: Re: How to marshall values as elements?
>
> See @XmlElementRef, you can have JAXBElement<SomeElement> where you
> can provide the name dynamically.
>
> On Thu, May 5, 2011 at 2:34 PM, Markus Karg <karg_at_quipsy.de> wrote:
> > I have a possibly strange question: How can I dynamically set
> elements
> > names?
> >
> >
> >
> > I need to create this:
> >
> >
> >
> > <SomeOuterElement>
> >
> >                 <foo>val1</foo>
> >
> >                 <bar>val2</bar>
> >
> > </SomeOuterElement>
> >
> >
> >
> > Looks easy, but the actual names "foo" and "bar" are not given
> statically,
> > but must change with each instance at runtime.
> >
> >
> >
> > Example:
> >
> >
> >
> > @XmlRootElement public class SomeOuterElement {
> >
> >     @XmlElement public List<SomeInnerElement> content;
> >
> > }
> >
> >
> >
> > public class SomeInnerElement {
> >
> >    public name; // contains "foo" or "bar"
> >
> >   public value; // contains "val1" or "val2"
> >
> > }
> >
> >
> >
> > Neither "foo" nor "bar" do exist as classes, those are just Strings
> which
> > have to get transported (don't ask why I want to do that -- it's part
> of
> > WebDAV's crazy spec).
> >
> >
> >
> > How to achieve that?
> >
> >
> >
> > Thanks!
> >
> > Markus