users@jaxb.java.net

Re: Unexpected class cast exception when using xs:anySimpleType

From: Luc Moreau <L.Moreau_at_ecs.soton.ac.uk>
Date: Tue, 06 Dec 2011 16:21:29 +0000

On 12/06/2011 03:52 PM, Wolfgang Laun wrote:
> 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
>
Hi,
Yes, javax.xml.namespace.QName
It worked well with the first schema, the jaxb marshaller handled
the QName properly, generating:
<ex:demo xsi:type="xsd:QName">prim:align_warp</ex:demo>
and making use of the prefix prim, which I had declared.

I noticed a similar class cast exception for a java.net.URI instance too.

Regards,
Luc