Amila Suriarachchi wrote:
On Tue, Jan 5, 2010 at 12:06 PM, Dennis Sosnoski <d...@sosnoski.com
<mailto:d...@sosnoski.com>> wrote:
Hi Amila,
It's definitely best to use minOccurs=1 for primitives.
nillable=true is *not* a good choice in general, and I'd recommend
you instead go with minOccurs=0 for object types.
Why is nillable=true bad? 1. It requires the element to still be
present in the message, adding unnecessary bloat (including the
xsi namespace definition and usage) and confusion for human
viewers of the message. 2. If required attributes are defined for
the element (not an issue for POJO deployment, since it doesn't
use attributes, but applicable in terms of the general use of
nillable=true) those attributes need to be present even with
xsi:nil=true in the document. minOccurs=0 is a cleaner
representation of optional values.
if we use minOccurs=0 instead of nillable=true does that fix the issue
given here[1]. Currently POJO gives preference to nillable=true when
returning null objects.
thanks,
Amila.
[1] https://issues.apache.org/jira/browse/AXIS2-3300
I think the .Net people prefer using nillable=true, for no good reason
that I've ever seen presented - somehow they got the idea early on that
xsi:nil="true" in an instance document is equivalent to a null value in
code. It's not - required attributes still need to be present on the
element, as mentioned before, and the element cannot be an abstract
element in the schema definition (unlike in code, where you commonly use
references with abstract types to hold either a null or an instance of
any of the possible matching concrete types).
I'd say it's always a bad idea to specify *both* minOccurs="0" and
nillable="true". I don't know offhand what .Net does if you only specify
minOccurs="0", but from the discussion it sounds like it would probably
still generate the flag variables - so if you want the schemas to be
optimized for .Net you're probably better off using nillable="true" to
fit with their misconceptions.
- Dennis