users@jaxb.java.net

Re: Unexpected class cast exception when using xs:anySimpleType

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 6 Dec 2011 16:52:26 +0100

On 06/12/2011, Luc Moreau <L.Moreau_at_ecs.soton.ac.uk> wrote:
> Hi,
> public JAXBElement<TypedLiteral> createDemo(TypedLiteral value) {
> return new JAXBElement<TypedLiteral>(_Demo_QNAME,
> TypedLiteral.class, null, value);
> }
>
> Using the method to generate the instance, the following exception (see
> below) is
> thrown when serializing my java beans. Looking at the source code,
> there seems to an expectation that the content of my value variable
> (with @XmlSchemaType(name = "anySimpleType")) should be of type
> String. My code fails when I provide a QName (with a view to generate
> the following instance)
>
> <ex:demo xsi:type="xsd:QName">prim:align_warp</ex:demo>
>

I presume that you "provide a QName" as in javax.xml.namespace.QName?
Even if an object of this class would be acceptable, it would not generate
what you expect; QName.toString() yields '{'+uri+'}'+local, i.e., not
the prefix.

I think that - for marshalling - you'll even have to resort to the
manual composition of a JAXBElement.

-W