aka*_*spi 2 java jaxb unmarshalling
我在尝试解组 XML 时遇到了一个严重的问题。起初,成员元素的“值”属性中仅包含 Integer(如第一个 'EnumType' 元素),但是,现在另一个 'EnumType' 以字符串作为值出现 - 我得到了下面的 NullPointerException。
请注意,Member.java 中的“value”成员最初来自“int”类型(当仅接受 Integer 作为 Member 元素的值时)并且它工作正常。只有当我将它更改为 Object (我想这是我的问题的根源)时 - 出现以下异常。
XML:
<EnumType Name="Genre" UnderlyingType="Edm.Int32">
<Member Name="ACTION" Value="0"/>
<Member Name="COMEDY" Value="1"/>
</EnumType>
<EnumType Name="Rating" UnderlyingType="Edm.String">
<Member Name="RatingA" Value="G"/>
<Member Name="RatingB" Value="PG"/>
</EnumType>
Run Code Online (Sandbox Code Playgroud)
枚举类型
@XmlRootElement
public class EnumType {
@XmlElement(name = "Member", namespace = "http://schemas.microsoft.com/ado/2009/11/edm")
private List<Member> members = new LinkedList<Member>();
public List<Member> getMembers() {
return members;
}
}
Run Code Online (Sandbox Code Playgroud)
会员.Java
@XmlRootElement
public class Member {
@XmlAttribute(name = "Name")
private String name;
@XmlAttribute(name = "Value")
private Object value;
public String getName() {
return name;
}
public Object getValue() {
return value;
}
}
Run Code Online (Sandbox Code Playgroud)
解组上述 XML 时,我收到此 NullPointerException:
java.lang.NullPointerException at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor.get(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty.(Unknown来源)位于 com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(未知来源),位于 com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(未知来源)。 sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal。 bind.v2.runtime.property.ArrayElementProperty.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at阳光反射。NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property。 PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source)在 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) 在 com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.(Unknown Source) 在 com.sun。 xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect。NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property。 PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source)在 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) 在 com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.(Unknown Source) 在 sun.reflect。 NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect。DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) at com.sun。 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2 处的 xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) .runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect。 NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect。Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown来源)位于 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(未知来源),位于 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(未知来源),位于 com.sun。 com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source) at com.sun.xml.internal.bind 处的 xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown Source) .v2.ContextFactory.createContext(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl。invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at javax.xml.bind.ContextFinder.newInstance(Unknown Source) at javax.xml.bind.ContextFinder.newInstance(Unknown Source) at javax。 xml.bind.ContextFinder.find(Unknown Source) at javax.xml.bind.JAXBContext.newInstance(Unknown Source) at javax.xml.bind.JAXBContext.newInstance(Unknown Source) at com.sap.ndb.studio.rdl。 csdlparser.jaxb.JAXBParser.load(JAXBParser.java:26) 在 com.sap.ndb.studio.rdl.datapreview.functions.LoadGRDL.function(LoadGRDL.java:59) 在 org.eclipse.swt.browser.WebSite。 Invoke(WebSite.java:773) at org.eclipse.swt.browser.WebSite$7.method6(WebSite.java:129) at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:119) ) 在 org.eclipse.swt.internal.win32.OS。DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756) at org.eclipse。 ui.internal.Workbench.runEventLoop(Workbench.java:2701) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java) :2499) 在 org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679) 在 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) 在 org.eclipse.ui .internal.Workbench.createAndRunWorkbench(Workbench.java:668) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java) :124) 在 org.eclipse.equinox.internal.app。位于 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) 的 EclipseAppHandle.run(EclipseAppHandle.java:196) 位于 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start( EclipseAppLauncher.java:79) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353) 在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180) 在 sun .reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org .eclipse.equinox.launcher.Main.invokeFramework(Main.java:629) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584) at org.eclipse.equinox.launcher.Main.run(Main.java:1438) 在 org.eclipse.equinox.launcher.Main.main(Main.java:1414)
有任何想法吗?:(
当您使用 注释 Object 类型的字段/属性时,JAXB RI 将抛出该异常@XmlAttribute。就像你在Member课堂上一样:
@XmlAttribute(name = "Value")
private Object value;
Run Code Online (Sandbox Code Playgroud)
想要查询更多的信息
| 归档时间: |
|
| 查看次数: |
3635 次 |
| 最近记录: |