users@jaxb.java.net

Re: xs:ID constructor issue

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 12 May 2009 16:27:52 +0200

You'll get a class that's annotated with |XmlRootElement by declaring an
element with the name="MyElement" and an anonymous type, like so:

<xs:element name="MyElement">
  <xs:complexType>
    <xs:sequence>
      <xs:element .../>
    </xs:sequence>
    <xs:attribute .../>
  </xs:complexType>
</xs:element>

But I don't think that this will save your problem. True, you'll have a
List<MyElement> instead of a List<Object>, but if you supply MyElement
objects, marshalling will just serialize the element and not generate the
xs:IDREF srings from the object's Id property.

-W

On Tue, May 12, 2009 at 11:31 AM, nicolas de loof
<nicolas.deloof_at_gmail.com>wrote:

> 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
>>>
>>
>>
>