users@jaxb.java.net

Re: marshalling and unmarhalling a sequence of any element

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Fri, 28 Sep 2007 12:23:04 +0200

Hi.

> I am encountering a problem mashalling and unmasrhalling data containing a
> List of any objects, such as:
>
> <xs:complexType name="MEVendorExtensions_T">
> <xs:sequence>
> <xs:any namespace="##any" processContents="lax"
> minOccurs="3" maxOccurs="unbounded" />
> </xs:sequence>
> </xs:complexType>.
>
> JAXB converts an annotation like this in an ArrayList of object.
> I have a question.
> How can I marshall and unmarshall some data in this list of objects?

JAXB does it for you, if your schema allows it.

> I have
> tried marshalling a complex type encapsulating it in a JAXBElement in ths
> way:
>
> JAXBElement<String> jxNameAndStrVal =
> new JAXBElement<String>(new QName("tmf854.v1"),
> String.class,
>
> elementToPass);

Why JAXBElement<String> and String.class if you have a complex type?

> the marshalling seems to work fine ( the SOAP message seems formatted
> correct).
>
> Anyway when the client receives the data he get the elements encapsulated in
> a xerces NMElement, and he cannot recover the class of the object he gets.
> (I noticed the "type" in the nmelement is null).

Seems like the content simply can't be unmarshalled. If you include
some elements as contents of xsd:any, they should be unmarshallable
with given schema - this especially means there must be an appropriate
root/global element declared.
Otherwise unmarshalling will fail and JAXB will simply add the
contents as DOM elements.

See my earlier post as well.

Bye.
/lexi