Change element name of annotated JAXB subclass

I am trying to create a jaxb class hierarchy for a web services domain. It’s inconvenient for me that a subclass that overrides the getter method in the superclass can change the name of the element that JAXB returns, but the superclass alone is also written to the output. I am wondering if there is a way to suppress a getter in a superclass.

code:

@XmlType class SuperClass { @XmlElement(name = "Name") public String getName(){} } @XmlType class SubClass extends SuperClass { @Override @XmlElement(name = "CoolName") public String getName(){} } 

When I add a SubClass element to XmlRootElement, the XML output contains two elements, <Name> and <CoolName>. Is there any way to suppress <Name> being marshaled?

+4
source share
1 answer

Do I need to have a name property on a SuperClass map? If you can’t just mark this property @XmlTransient.

 class SuperClass { @XmlTransient public String getName(){} } 
+2
source

All Articles