JAXB, marshalling sub-class that has the same rootNode name as the superclass

Posted by SCdF on Stack Overflow See other posts from Stack Overflow or by SCdF
Published on 2010-03-09T04:04:16Z Indexed on 2010/03/09 4:06 UTC
Read the original article Hit count: 371

Filed under:
|

Let's say I have this:

public class Foo {
  private String value;

  // <snip> getters and setters, constructors etc
}

And I also have this:

public class Bar extends Foo {
  private String anotherValue;

  // <snip> getters and setters, constructors etc
}

I want to be able to marshall this to a Bar object:

<foo>
  <value>smang</value>
  <anotherValue>wratz</anotherValue>
</foo>

I'm not in a position to check right now, but if I change the @XmlRootNode name of Bar to 'foo' will that work? Do I have to do anything more clever than that?

© Stack Overflow or respective owner

Related posts about jaxb

Related posts about java