users@jaxb.java.net

marshalling fails on SUBSTITUTED_BY_ANONYMOUS_TYPE error

From: Mr. Beeba <mr.beeba_at_volny.cz>
Date: Wed, 20 Aug 2008 10:31:22 +0200

Hi all,

I get the exception listed below (>>Instance of "ontologies.SensorBasicReport"
is substituting "java.lang.Object", but "ontologies.SensorBasicReport" is
bound to an anonymous type.<<) when marshalling my class ACLMessagingReport
(class + XSD schema attached) with one of its properties containing the class
SensorBasicReport (class + XSD schema attached). Basically, the property
ACLMessagingReport.content is declared as <xsd:anyType>, i.e. declared as
Object content in Java and when being marshalled it holds SensorBasicReport
class instance. In order to get @XMLRootElement annotation at
SensorBasicReport class (needed for other purposes), it is defined as
anonymous complex type (which is given by JAXB specs if I am correct). Though
when included into another XML it seems to cause problems - particularly, it
seems lik JAXB expects the SensorBasicReport to be of some specific type (any
type) except for anonyous type. Yet, I need the SensorBasicReport to be
annotated as @XMLRootElement.
Any idea how to put this together? Any way of modifying the
ACLMessagingReport.content type definition in XSD to allow inserting of
anonymus types?

Cheers,
Bebe



javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: Instance of "ontologies.SensorBasicReport" is
substituting "java.lang.Object", but "ontologies.SensorBasicReport" is bound
to an anonymous type.]
        at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:331)
        at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:257)
        at
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:96)
        at
net.sf.istcontract.aws.sensor.Sensor.submitObservation(Sensor.java:119)
        at
sensorsample.SensorSampleApp.sendSensorReport(SensorSampleApp.java:198)
        at sensorsample.SensorSampleView$11.run(SensorSampleView.java:333)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: com.sun.istack.SAXException2: Instance
of "ontologies.SensorBasicReport" is substituting "java.lang.Object",
but "ontologies.SensorBasicReport" is bound to an anonymous type.
        at
com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:244)
        at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:659)
        at
com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:150)
        at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
        at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:589)
        at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:312)
        at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
        at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
        ... 13 more