将 EclipseLink MOXy 与 Java 1.5 结合使用

发布于 2024-09-25 20:48:41 字数 199 浏览 4 评论 0原文

有没有人有 EclipseLink MOXy(我正在使用 eclipselink 2.1.0)来使用 Java 5?每当我尝试解组时,我都会在 org.eclipse.persistence.oxm.record.UnmarshalRecord 的 startCDATA() 方法中收到空指针异常(xPathNode 为空)。完全相同的代码和 XML 在 Java6 中运行得非常好。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2024-10-02 20:48:41

我是 MOXy 的技术主管。您能提供堆栈跟踪吗?有关您的用例的更多详细信息?

有关 MOXy 的更多信息,请查看:

回复您的更新:

我我无法重现这一点。我正在使用以下环境。您是否有可以发送的测试用例([email protected])或指出我在做什么不同?:

  • JDK: 1.5.0_22
  • EclipseLink 2.1.0

以下模型:

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;
    }

}

演示代码:

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);
    }
}

和 XML:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文