users@jaxb.java.net

marshalling problem

From: Frank <fgeck_at_optonline.net>
Date: Tue, 14 Nov 2006 20:27:07 -0500

I have a problem with marshaling an object as a complex type is of any
type (see schema below). I'm trying to just set the element value to a
string and get the error below.


Here is the error:

15625 [pool-1-thread-1] FATAL csds.mesh.CsfMeshXrs - :processGetDocReq,
Problem creating the get doc response
javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "java.lang.String"
as an element because it is missing an @XmlRootElement annotation]
    at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:295)
    at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:221)
    at
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:77)
    at csds.mesh.MeshUtil.createMsgToSend(MeshUtil.java:926)


The relevant part of the schema is as follows:
    <xsd:element name="getDocResponse">
        <xsd:annotation>
            <xsd:documentation>
    Response from internal MeSH to XRS containing a valid document.
    </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="Time" type="xsd:dateTime"/>
                <xsd:element name="Item">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:any namespace="##any"
processContents="strict"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

Code segment.
       Object msgObj; //value passed in

        JAXBContext jc = JAXBContext.newInstance("csds.message");;
        StringWriter result = new StringWriter();
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(msgObj, result); //Fails here
        msgStr = result.toString();