Ahhh...well that is where things do get tricky.
public class PropertyValue<T>
{
protected PropertyTypes type;
@XmlJavaTypeAdapter(PropertyAdapter.class)
private T value;
public T getValue()
{
return value;
}
public void setValue( T v )
{
value = v;
}
...
}
-----Original Message-----
From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Sent: Tuesday, December 19, 2006 1:33 PM
To: users_at_jaxb.dev.java.net
Subject: Re: IllegalAnnotationsException when @XmlValue and
@XmlJavaTypeAdapter both present in xjc generated code.
How does the definition of PropertyValue look like?
Scudieri, Chris (IT) wrote:
> Usage of baseType is not well documented so I may be outside of the
> intention of the Spec.
> However what XJC is generating is extremely close to what I am looking
> for. I am trying to get an XmlAdapter to marshal/unmarshall the value
> of the Property element and have run into the Following issue:
>
> Schema snippet:
>
> <xs:complexType name="Property" >
> <xs:annotation><xs:appinfo>
> <jaxb:property>
> <jaxb:baseType>
> <xjc:javaType name="com.test.PropertyValue"
> adapter="com.test.PropertyAdapter" />
> </jaxb:baseType>
> </jaxb:property>
> </xs:appinfo></xs:annotation>
>
> <xs:simpleContent>
> <xs:extension base="PropertyType">
> <xs:attribute name="type" type="PropertyTypes" />
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>
>
> Where:
> PropertyType is essentially anySimpleType PropertyTypes is a string
> enum
>
>
>
> Generated Property.java:
> public class Property {
>
> @XmlValue
> @XmlJavaTypeAdapter(PropertyAdapter.class)
> protected PropertyValue value;
> @XmlAttribute
> protected PropertyTypes type;
>
>
> However attempting to create a context throws an
> IllegalAnnotationsException:
>
> com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
> IllegalAnnotationExceptions @XmlAttribute/_at_XmlValue need to reference
> a Java type that maps to text in XML.
> this problem is related to the following location:
> at protected com.test.PropertyValue
> com.test.generated.Property.value
> at com.test.generated.Property
> at public com.test.generated.Property
> com.test.generated.ObjectFactory.createProperty()
> at com.test.generated.ObjectFactory
>
> at
> com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(
> Il
> legalAnnotationsException.java:66)
> at
> com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContext
> Im
> pl.java:405)
> at
>
com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:
> 253)
> at
>
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:84)
> at
>
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:66)
> at
> com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:1
> 32
> )
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j
> av
> a:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess
> or
> Impl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at
> javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
> at javax.xml.bind.ContextFinder.find(ContextFinder.java:285)
> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com
--------------------------------------------------------
NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.