users@jaxb.java.net

InstantiationException when unmarshalling fpml instance document

From: Hunter Stern <vonrosen2000_at_yahoo.com>
Date: Mon, 10 Apr 2006 22:15:58 -0700 (PDT)

the java code to unmarshal is:

        JAXBContext jc =
JAXBContext.newInstance("com.riskman.fpml");

        Unmarshaller u = jc.createUnmarshaller();

        u.setEventHandler(new
DefaultValidationEventHandler());

        u.unmarshal( new FileInputStream(
"C:\\downloads\\critical\\riskmansite\\hyperjaxbtest\\xml\\ird_ex01_vanilla_swap.xml"
) );

The com.riskman.fpml.DataDocument class is in the
classpath.

here is the dump from the defaulteventhandler:

DefaultValidationEventHandler: [ERROR]: unrecognized
type name: DataDocument
     Location: line 7
javax.xml.bind.UnmarshalException: unrecognized type
name: DataDocument
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:523)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:199)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:194)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.XsiTypeLoader.parseXsiType(XsiTypeLoader.java:58)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.XsiTypeLoader.startElement(XsiTypeLoader.java:30)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:19)
        at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$IntercepterLoader.startElement(ElementBeanInfoImpl.java:173)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:367)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:345)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:117)
        at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
Source)
        at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
Source)
        at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown
Source)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
        at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
        at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
        at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
        at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:200)
        at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:173)
        at
javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
        at
javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
        at MainTest.deserializeXML(MainTest.java:54)
        at MainTest.process(MainTest.java:40)
        at MainTest.main(MainTest.java:28)
javax.xml.bind.UnmarshalException: unrecognized type
name: DataDocument




Hunter Stern wrote:
> The Document class maps to the abstract element
> Document:
>
> <xsd:complexType name="Document" abstract="true">
> <xsd:annotation>
> <xsd:documentation xml:lang="en">The abstract
base
> type from which all FpML compliant messages and
> documents must be derived.</xsd:documentation>
> </xsd:annotation>
> <xsd:attributeGroup
ref="StandardAttributes.atts"/>
> </xsd:complexType>
>
> The Document class is implemented by the
DataDocument
> class which is the element specified by the "type"
> attribute in the instance document, <FpML
> version="4-1" xsi:type="DataDocument", why doesn't
> jaxb try to instantiate the DataDocument class
instead
> of Document?

It should. It must be failing to resolve
xsi:type="DataDocument".

1. register ValidationEventHandler on the unmarshaller
and dump reported
errors.
2. how are you creating JAXBContext. Does it know
about the DataDocument
class?