MOXy @XmlPath is ignored

I have a very simple class with two fields: String sourceAddress and int port.

I want them to appear on source / address and source / port nodes instead of jaxb default sourceAddress and sourcePort.

Therefore, I use the annotation MOXy @XmlPath.

The problem is that the annotation is simply ignored, and I get the XML file "jaxb default":

<szk> <sourceAddress>test</sourceAddress> <sourcePort>10000</sourcePort> </sz> 

in advance for any help Agostino

  import javax.xml.bind. *;
 import javax.xml.bind.annotation. *;
 import org.eclipse.persistence.jaxb.JAXBContext;
 import org.eclipse.persistence.oxm.annotations.XmlPath;

 @XmlRootElement
 @XmlAccessorType (XmlAccessType.FIELD)
 public class SZK {

     @XmlPath ("source / address")
     private String sourceAddress;
     @XmlPath ("source / port")
     private int sourcePort;

     public static void main (String [] args) throws JAXBException {

         SZK k = new SZK ();
         k.sourceAddress = "test";
         k.sourcePort = 10000;

         javax.xml.bind.JAXBContext jc = JAXBContext.newInstance (SZK.class);
         Marshaller m = jc.createMarshaller ();
         m.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
         m.marshal (k, System.out);

     }

 }

+4
source share
1 answer

The most likely cause of this problem is that you are missing the jaxb.properties file to indicate that EclipseLink MOXy should be used as a JAXB provider. The jaxb.properties file must be placed in the same package as your domain model and contain the following entry:

 javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory 

Additional Information:

+6
source

All Articles