I am trying to reproduce your problem, but still have not been successful. Do you see where I am doing something other than you? The following is sample code:
A
import javax.xml.bind.annotation.*; @XmlAccessorType(XmlAccessType.FIELD) public abstract class A { public abstract C getC(); public abstract void setC(C c); }
IN
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; } }
WITH
public class C { }
Demo
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); } }
Output
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
Based on your comments:
- B does not inherit XmlAccessorType settings.
- This is not an abstract method that you need to point out @XmlTransient, but the field used to implement the accessor in class B.
What follows is what class B looks 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; } }
source share