Skip to main content

JAXB: Unable to Unmarshall Substituted Type

2 replies [Last post]
johnson5523
Offline
Joined: 2005-09-29

I am having problems when trying to unmarshall a substituted type. It appears as if the unmarshaller is trying to instantiate an instance of the Base type which is abstract. I am not sure if I have found a bug or am missing something, but I am at my wits end. Please help!
Thanks!

Here are the details:

I am getting the following exception:

[java] javax.xml.bind.UnmarshalException: Unable to create an instance of jaxbtest.xmlobjects.Base
[java] - with linked exception:
[java] [java.lang.InstantiationException]
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:1150)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.AbstractUnmarshallingEventHandlerImpl.reportError(AbstractUnmarshallingEventHandlerImpl.java:86)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext.java:266)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.AbstractUnmarshallingEventHandlerImpl.spawnChild(AbstractUnmarshallingEventHandlerImpl.java:154)
[java] at com.sun.xml.bind.v2.runtime.property.Unmarshaller$SpawnChildHandler.handle(Unmarshaller.java:528)
[java] at com.sun.xml.bind.v2.runtime.property.Unmarshaller$EpsilonHandler.activate(Unmarshaller.java:74)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.setCurrentHandler(UnmarshallingContext.java:527)
[java] at com.sun.xml.bind.v2.runtime.property.Unmarshaller$EnterElementHandler.act(Unmarshaller.java:354)
[java] at com.sun.xml.bind.v2.runtime.property.Unmarshaller$EnterElementHandler.enterElement(Unmarshaller.java:344)
[java] at com.sun.xml.bind.v2.runtime.property.ElementDispatcher.enterElement(ElementDispatcher.java:122)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:384)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:329)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:99)
[java] at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
[java] at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
[java] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
[java] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
[java] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
[java] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
[java] at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
[java] at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:182)
[java] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:135)
[java] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:182)
[java] at jaxbtest.JaxbTest.main(JaxbTest.java:18)
[java] Caused by: java.lang.InstantiationException
[java] at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
[java] at java.lang.reflect.Constructor.newInstance(Unknown Source)
[java] at com.sun.xml.bind.v2.ClassFactory.create0(ClassFactory.java:70)
[java] at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.createInstance(ClassBeanInfoImpl.java:246)
[java] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext.java:260)
[java] ... 22 more

when executing the following code:

public class JaxbTest
{
public static void main(final String[] arguments)
{
try
{
JAXBContext jc = JAXBContext.newInstance("jaxbtest.xmlobjects");

Unmarshaller u = jc.createUnmarshaller();

u.unmarshal(new FileInputStream("jaxbtest.xml"));
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
}

Here is the jaxbtest.xml file:

<?xml version="1.0" encoding="UTF-8"?>

Here is the jaxbtest.xsd:

<?xml version="1.0" encoding="UTF-8"?>

Here is the jaxbtest.xjb file:

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09

Please file an issue to http://jaxb.dev.java.net/ issue tracker.

Thanks!

ricoatray
Offline
Joined: 2007-07-17

Has this been fixed? I am getting the same problem in JAXB 2.0.5 that comes with BEA WebLogic 10.

Thanks.