I'm not sure I fully understand your question, but I believe you are experiencing a problem when there is a dash in the element name. Below is an example that may help.
bindings.xml
Below is an example of EclipseLink JAXB (MOXy)'s XML binding file. The xml-path
for the mapping to the email
property contains a dash E-Mail/text()
.
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="forum10435322">
<java-types>
<java-type name="Root">
<xml-root-element/>
<java-attributes>
<xml-element java-attribute="email" xml-path="E-Mail/text()"/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
Root
Below is the domain object I'll use for this example. It does not contain any annotations.
package forum10435322;
import java.util.List;
public class Root {
private List<String> email;
public List<String> getEmail() {
return email;
}
public void setEmail(List<String> email) {
this.email = email;
}
}
jaxb.properties
In order to specify MOXy as the JAXB provider you need to add a file called jaxb.properties
in the same package as your domain classes with the following entry:
javax.xml.bind.context.factory = org.eclipse.persistence.jaxb.JAXBContextFactory
Demo
Below is some demo code demonstrating how to bootstrap a JAXBContext
using MOXy's external metadata.
package forum10435322;
import java.io.File;
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, "forum10435322/bindings.xml");
JAXBContext jc = JAXBContext.newInstance(new Class[] {Root.class}, properties);
File xml = new File("src/forum10435322/input.xml");
Unmarshaller unmarshaller = jc.createUnmarshaller();
Root root = (Root) unmarshaller.unmarshal(xml);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
}
}
input.xml/Output
The following is the input and output for this example.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<E-Mail>[email protected]</E-Mail>
<E-Mail>[email protected]</E-Mail>
</root>