I would, in the scenario below, like the binding of java-type name="SubClass" to be applied to set the text field on SuperClass. However it is not. Is there a problem with overriding the bindingsA.xml? According to the Overriding rules:
Quote:If the same java-type occurs in multiple files, any values that are set in the later file, will override values from the previous file
What do I need to do to make it work?
Input:
<?xml version="1.0" encoding="UTF-8"?>
<a text="A text">B text</a>
Bindings A:
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="test">
<java-types>
<java-type name="SuperClass">
<xml-root-element name="a"/>
<java-attributes>
<xml-element java-attribute="text" xml-path="@text" />
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
Bindings B:
<?xmlversion="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="test">
<java-types>
<java-type name="SuperClass" xml-transient="true"></java-type>
<java-type name="SubClass">
<xml-root-element name="a"/>
<java-attributes>
<xml-element java-attribute="text" xml-path="text()" />
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
Classes:
public class SuperClass {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
public class SubClass extends SuperClass { }
Demo:
Map<String, Object> jaxbContextProperties = new HashMap<String, Object>(1);
List<String> bindings = new LinkedList<String>();
bindings.add("bindingsA.xml");
bindings.add("bindingsB.xml");
jaxbContextProperties.put(JAXBContextProperties.OXM_METADATA_SOURCE, bindings);
JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[] {SuperClass.class}, jaxbContextProperties);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
SuperClass superClass = (SuperClass)unmarshaller.unmarshal(new File("input.xml"));
System.out.println(superClass.getText());
Output:
[EL Warning]: 2013-07-31 16:08:07.771--Ignoring attribute [text] on class [SubClass] as no Property was generated for it.
A text