users@jaxb.java.net

Re: marshalling problem

From: Dmitri Colebatch <dim_at_colebatch.com>
Date: Wed, 15 Nov 2006 12:37:58 +1100

Isn't the problem here that msgObj is a String?

On 11/15/06, Frank <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
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>