> -----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
On my first try this didn't work, because I only specified the "name" attribute of each nested @XmlElement. Once I added the "type" value (which I had assumed it would figure out), it worked fine. > -----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.
