users@jaxb.java.net

Re: marshalling problem

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

Actually msgObj is a getDocResponse. I wanted to create (maybe
incorrectly ) a generic marshaller to a string of a root element/msg.

Dmitri Colebatch wrote:

> Isn't the problem here that msgObj is a String?
>
> On 11/15/06, Frank <fgeck_at_optonline.net <mailto:fgeck_at_optonline.net>>
> wrote:
>
> 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();
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> <mailto:users-unsubscribe_at_jaxb.dev.java.net>
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> <mailto:users-help_at_jaxb.dev.java.net>
>
>