users@jaxb.java.net

xs:ID constructor issue

From: nicolas de loof <nicolas_at_apache.org>
Date: Mon, 11 May 2009 15:10:39 +0200

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