users@jaxb.java.net

Re: xs:ID constructor issue

From: nicolas de loof <nicolas.deloof_at_gmail.com>
Date: Tue, 12 May 2009 11:31:05 +0200

Thanks a lot, this looks far better
I still have an issue during marshalling :
unable to marshal type "...MyElement" as an element because it is missing an
@XmlRootElement annotation]

As this code is generated from WSDL, I wonder how I can control the types
that get annotated @XmlRootElement

Best regards,
Nicolas

2009/5/11 Wolfgang Laun <wolfgang.laun_at_gmail.com>

> For obtaining typed references you just use
> <jaxb:baseType name="MyElement"/>
> (The javaType=<type> *substitutes* a different type, which is something
> else altogether.)
>
> Also, the minOccurs="0" on the referenced object's ID doesn't make sense,
> the ID is required.
>
> -W
>
>
>
> On Mon, May 11, 2009 at 3:10 PM, nicolas de loof <nicolas_at_apache.org>wrote:
>
>> Hello,
>> My WSDL/XSD uses a ID-ref to avoid cycles in data structure.
>>
>> To keep strong-typed attributes in the generated java code I've added some
>> jaxb binding elements :
>>
>> <xs:element name="listeElements" type="xs:IDREFS" minOccurs="1"
>> maxOccurs="unbounded">
>> <xs:annotation>
>> <xs:appinfo>
>> <jaxb:property>
>> <jaxb:baseType>
>> <jaxb:javaType name="MyElement"/>
>> </jaxb:baseType>
>> </jaxb:property>
>> </xs:appinfo>
>> </xs:annotation>
>> </xs:element>
>>
>> And added an xs:ID attribut on the "MyElement" type :
>>
>> <xs:complexType name="MyElement">
>> <xs:sequence>
>> <xs:element name="id" type="xs:ID" minOccurs="0"/>
>> ...
>>
>> The generated code is fine (I'm using apache CXF, that itself uses xjc) :
>>
>> @XmlElement(required = true, type = String.class)
>> @XmlJavaTypeAdapter(Adapter1 .class)
>> @XmlSchemaType(name = "IDREFS")
>> protected List<MyElement> listeElements;
>>
>> BUT the generated Adapter1 expect the tager MyElement class to have an
>> ID-constructor :
>>
>> public class Adapter1
>> extends XmlAdapter<String, MyElement>
>> {
>> public MyElement unmarshal(String value) {
>> return new MyElement(value);
>> }
>>
>>
>> There is no constructor generated in MyElement. Did I missed something ?
>>
>> Best regards,
>> Nicolas
>>
>
>