users@jaxb.java.net

Optional List based attributes and marshalling

From: Ian Carr <ian.carr_at_focus-solutions.co.uk>
Date: Wed, 22 Mar 2006 15:58:34 -0000

I have a query about the way JAXB is marshalling an optional list based attribute.

 

My schema contains an optional attribute of type xs:IDREFS, using the EA3 build of JAXB 2 (jaxb-ri-20051223) I get the generated classes I would expect with this attribute being given an accessor with the following signature:

 

public List<Object> getTwo() {

if (two == null) {

two = new ArrayList<Object>();

}

return this.two;

}

 

If I create and marshal an instance of the class it produces the expected output:

 

<X/>

 

However if the accessor is invoked before marshalling it produces the following output, with an empty 'two' attribute:

 

<X two=""/>

 

This isn't a major issue, but one of my validators then complains that the empty IDREFS attribute is not legal. Looking at the XML schema spec it says:

 

"The ˇvalue spaceˇ <http://www.w3.org/TR/xmlschema-2/#dt-value-space> of IDREFS is the set of finite, non-zero-length sequences of IDREF <http://www.w3.org/TR/xmlschema-2/#IDREF> s"

 

Which if I am reading it correctly means that a zero-length or "" value is incorrect.

 

Is there something I am not doing in my schema, custom binding script or code that would suppress this empty attribute?

 

Ian Carr