java – JAXB 2. x: Abstract methods are grouped into properties
I have an abstract root class. Let's say a
I have several implementation class extensions a
A has field annotation and some @ xmlelement annotation attributes
A also has abstract methods
When grouping (b extends a), the values returned by the abstract method are grouped as attributes Not expected, right?
@XmlAccessorType(XmlAccessType.FIELD) public abstract class SpecialProfile extends ContentNodeBean { @XmlElement(name="do-index",namespace="my") private boolean doIndex = false; public abstract SpecialProfileType getSpecialProfileType(); ... getters and setters for properties ... }
Does anyone have the same problem and how to solve it?
I'm using org eclipse. persistence. moxy 2.1. two
Solution
I tried to recreate your problem, but so far I have failed Can you see I'm doing something different from you? Here is my sample code:
One
import javax.xml.bind.annotation.*; @XmlAccessorType(XmlAccessType.FIELD) public abstract class A { public abstract C getC(); public abstract void setC(C c); }
B
import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class B extends A { private C c; @Override public C getC() { return c; } @Override public void setC(C c) { this.c = c; } }
C
public class C { }
demonstration
import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import org.eclipse.persistence.Version; public class Demo { public static void main(String[] args) throws Exception { System.out.println(Version.getVersionString()); JAXBContext jc = JAXBContext.newInstance(B.class); System.out.println(jc); B b = new B(); b.setC(new C()); Marshaller marshaller = jc.createMarshaller(); marshaller.marshal(b,System.out); } }
yield
2.1.2.v20101206-r8635 org.eclipse.persistence.jaxb.JAXBContext@100ab23 <?xml version="1.0" encoding="UTF-8"?> <b xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="b"><c/></b>
UPDATE
According to your opinion:
>B does not inherit the xmlaccessortype setting of A. > The tag @ xmltransient is not an abstract method, but a field used to implement an accessor on class B
Here is what class B should look like:
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class B extends A { @XmlTransient private C c; @Override public C getC() { return c; } @Override public void setC(C c) { this.c = c; } }