Community
Participate
Working Groups
There is currently an issue with oxm.xml and @XmlAccessorType.NONE. I will demonstrate the issue with the following example: If you were going to map this use case with JAXB/MOXy annotations you could set `@XmlAccessorType(XmlAccessType.NONE)` on the `A` class and do something like: **Using Annotations** ***A*** package forum8727402; import javax.xml.bind.annotation.*; @XmlAccessorType(XmlAccessType.NONE) public abstract class A { public abstract String getX(); } ***B*** package forum8727402; import javax.xml.bind.annotation.*; import org.eclipse.persistence.oxm.annotations.XmlPath; @XmlRootElement public class B extends A { @XmlPath("a/b/c/text()") private String x; public B() { x = "Hello World"; } @Override public String getX() { return x; } @XmlElement public String getCalculatedValue() { return "Calculated Value"; } } ***Demo*** package forum8727402; import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(B.class); B b = new B(); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(b, System.out); } } ***Output*** <?xml version="1.0" encoding="UTF-8"?> <b> <a> <b> <c>Hello World</c> </b> </a> <calculatedValue>Calculated Value</calculatedValue> </b> <hr/> **Using MOXy's External Mapping File** ***oxm.xml*** Below is a [MOXy external mapping file][3] that represents the equivalent of the previously shown annotations: <?xml version="1.0" encoding="UTF-8"?> <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm" package-name="forum8727402"> <java-types> <java-type name="A" xml-accessor-type="NONE"/> <java-type name="B"> <xml-root-element/> <java-attributes> <xml-element java-attribute="x" xml-path="a/b/c/text()"/> <xml-element java-attribute="calculatedValue"/> </java-attributes> </java-type> </java-types> </xml-bindings> ***Demo*** The code below demonstrates how to reference the mapping file: package forum8727402; import java.util.*; import javax.xml.bind.*; import org.eclipse.persistence.jaxb.JAXBContextFactory; public class Demo { public static void main(String[] args) throws Exception { Map<String, Object> properties = new HashMap<String, Object>(1); properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, "forum8727402/oxm.xml"); JAXBContext jc = JAXBContext.newInstance(new Class[] {A.class, B.class}, properties); B b = new B(); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(b, System.out); } } ***Output*** [EL Warning]: 2012-01-04 14:45:46.366--Ignoring attribute [x] on class [forum8727402.xml.B] as no Property was generated for it. <?xml version="1.0" encoding="UTF-8"?> <b> <calculatedValue>Calculated Value</calculatedValue> </b>
Created attachment 212727 [details] Fix and test for Trunk
Created attachment 212730 [details] Fix and Test for 2.3
Attached patches checked in to Trunk and 2.3
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink