Search code examples
javajaxbeclipselinkjava-5moxy

Using EclipseLink MOXy with Java 1.5


Has anyone got EclipseLink MOXy (I'm using eclipselink 2.1.0) to work with Java 5? Whenever I try to unmarshal I get a null pointer exception in org.eclipse.persistence.oxm.record.UnmarshalRecord, in the startCDATA() method (xPathNode is null). The exact same code and XML works wonderfully in Java6.


Solution

  • I'm the tech lead for MOXy. Can you provide the stack trace & more details on your use case?

    For more information on MOXy check out:

    Re your update:

    I haven't been able to reproduce this on my end. I am using the following env. Do you have a test case you can send ([email protected]) or point out what I'm doing differently?:

    • JDK: 1.5.0_22
    • EclipseLink 2.1.0

    The following model:

    package cdata;
    
    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement
    public class Customer {
    
        private String firstName;
        private String lastName;
    
        public String getFirstName() {
            return firstName;
        }
    
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    
    }
    

    Demo code:

    package cdata;
    
    import java.io.File;
    
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Customer.class);
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            Customer customer = (Customer) unmarshaller.unmarshal(new File("src/cdata/input.xml"));
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(customer, System.out);
        }
    }
    

    And XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <customer>
        <firstName>Jane</firstName>
        <middleName><![CDATA[<?xml version="1.0"?>]]></middleName>
        <lastName>Doe</lastName>
    </customer>