JAXB 2.0 Marshaling Exception

Hello,

I ran into an error when trying marshal a java class. NullPointerException is caught when this line of code is executed. I previously used XJC to generate the Java classes including ObjectFactory.java in textjaxb.student package.

JAXBContext jaxbContext = JAXBContext.newInstance("testjaxb.student");

After searching for solution, I tried to use different method for loading ObjectFactory class into .netInstance(...);. I tried using thread/context classloader, testjaxb.student.ObjectFactory.class as parameter. But the problem still persist. Any suggestion will be helpful.

The stacktrace shows the following:

Exception in thread"main" java.lang.NullPointerException

at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName(PropertyInfoImpl.java:287)

at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName(PropertyInfoImpl.java:260)

at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl.getTypes(ElementPropertyInfoImpl.java:100)

at com.sun.xml.bind.v2.model.impl.RuntimeElementPropertyInfoImpl.getTypes(RuntimeElementPropertyInfoImpl.java:50)

at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.size(ElementPropertyInfoImpl.java:42)

at java.util.AbstractList$Itr.hasNext(AbstractList.java:416)

at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:139)

at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:49)

at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:41)

at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:189)

at com.sun.xml.bind.v2.model.impl.RegistryInfoImpl.<init>(RegistryInfoImpl.java:63)

at com.sun.xml.bind.v2.model.impl.ModelBuilder.addRegistry(ModelBuilder.java:232)

at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:201)

at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:352)

at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:350)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:349)

at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:215)

at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76)

at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55)

at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:124)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)

at javax.xml.bind.ContextFinder.find(ContextFinder.java:286)

at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)

at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)

at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)

Thank you very much.

T-ra

[3375 byte] By [T-raa] at [2007-10-3 11:44:13]
# 1

I had the same issue. Try using the SDK jars instead of which ever tool you are using for JAXB2.0.

These jars are from J2EE 5 SDK

Sun/SDK/lib/javaee.jar

Sun/SDK/lib/appserv-ws.jar

I believe you need to have 2.0 jars to resolve this exception. the 2.0 version does NOT create *Impl.java sources, jaxb.properties and *.ser resources even though the tutorial says so....

Hope this helps!

Let me know how it goes!

gahlawata at 2007-7-15 14:16:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

I had the same problem and resolved it by removing the elementFormDefault="qualified" form the schema tag.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns:tns="http://www.calpers.ca.gov/soa/2006-12-21/CommonData.xsd"

targetNamespace="http://www.calpers.ca.gov/soa/2006-12-21/CommonData.xsd"

elementFormDefault="qualified">

<xs:element name="commonData" type="tns:CommonDataType"/>

<xs:complexType name="CommonDataType">

<xs:sequence>

<xs:element name="defaultPayloadData" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:schema>

markpopea at 2007-7-15 14:16:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Yes, but how do you read the document's child elements. If you remove the elementFormDefault atrribute you will only be able to unmarshal the root element. Any child elements will be null.
helder_darochaa at 2007-7-15 14:16:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...