在XMLSerializer中从Java 6升级到Java 7时,JAXB marshaller抛出NullPointerException

时间:2014-01-27 22:47:08

标签: java xml jaxb jaxb2 spring-oxm

我已经搜索了互联网以寻求解决方案,但我不知所措,所以我希望有人可以在这里指出我正确的方向。

我的任务是将使用JAXB2的应用程序升级到Java 7。

由于我了解JVM 7可以运行Java 6编译代码,这是我首先尝试的,并且在com.sun.xml.internal.bind.v2.runtime.XMLSerializer类中遇到了Null Pointer Exception。

然后我在Java 7中重新编译了应用程序并再次运行同样的问题。

我正在使用以下Oracle JDK: Java SE 7u51 该应用程序还使用Spring OXM,它委托给JAXB。

这是在JAXB Marshaller实例上调用marshal时出现的Null Pointer Exception堆栈跟踪:

> java.lang.NullPointerException    at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:627)
>   at
> com.sun.xml.internal.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody(SingleElementLeafProperty.java:108)
>   at
> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:343)
>   at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:685)
>   at
> com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:54)
>   at
> com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:157)
>   at
> com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:144)
>   at
> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:343)
>   at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:582)
>   at
> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:325)
>   at
> com.sun.xml.internal.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:103)
>   at
> com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:144)
>   at
> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:343)
>   at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:582)
>   at
> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:325)
>   at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:483)
>   at
> com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:308)
>   at
> com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)
>   at
> org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:648)

也许我缺少一些额外的配置?

任何帮助表示赞赏。将根据需要提供更多信息。

谢谢

1 个答案:

答案 0 :(得分:2)

尝试包含jaxb-impl的参考实现,至少它解决了this guy with the same error的问题

<dependency>
   <groupId>com.sun.xml.bind</groupId>
   <artifactId>jaxb-impl</artifactId>
   <version>2.2.7</version>
</dependency>