> -----Original Message-----
> From: Sergey Beryozkin [mailto:[email protected]]
> Sent: Saturday, December 19, 2009 12:05 PM
> To: [email protected]
> Subject: RE: serializing subclass of base class gets base class name
in
> output
> 
> Hi
> 
> You may want to try @XmlElements listing Bar.class and Gork.class
> instead of @XmlElement(name = "foo"), let us know please if it helps

I assume that it would look something like this:

    @XmlElementWrapper(name = "childFoos")
//    @XmlElement(name = "foo")
    @XmlElements(value =
                 {...@xmlelement(name = "bar"),
                  @XmlElement(name = "gork")})
    private List<Foo>   childFoos;

I hope this is wrong, because it didn't do what I had hoped.
Originally, I had all the "foo" elements wrapped with "<foo>", although
they were actually subclasses of Foo.  When I made this change, I was
glad to see the first element in the test case output was "<gork>".
Unfortunately, when I looked at the data in the element, I could see it
should have been "<bar>".  I looked at the rest of the results, and all
of them were "<gork>", whether they should be or not.

> -----Original Message-----
> From: KARR, DAVID (ATTCINW) [mailto:[email protected]]
> Sent: 19 December 2009 19:50
> To: [email protected]
> Subject: serializing subclass of base class gets base class name in
> output
> 
> I had originally had a "Foo" class in my REST server which was
> serializing fine as "<foo>".  I then realized that this was really a
> base class, so I added the subclasses of it, which are "Bar" and
> "Gork".
> The declaration of the list of these is the following:
> 
>     @XmlElementWrapper(name = "childFoos")
>     @XmlElement(name = "foo")
>     private List<Foo>   childFoos;
> 
> When I serialize this, I get exactly what I specified here, such that
> each "Foo" element is a "foo".
> 
> What I want is to have a "<childFoos>" list, but each element will
> either be "<bar>" or "<gork>", depending on the subclass.  The data I
> have in each "foo" is correct, reflecting whether it was a "bar" or a
> "gork", but I want the wrapper to change based on that.
> 
> I tried to remove the "XmlElement" wrapper here, but that just
resulted
> in "<childFoos>" wrapping a list of "<childFoos>", not a mixture of
> "<bar>" or "<gork>" elements.

Reply via email to