Vallamshettla, Anand wrote:
> If a document with <BooleanTypeTag>hello</ BooleanTypeTag> is
> unmarshalled, Jaxb2 is setting the value to 'false'. Shouldn't the
value
> of the field be 'null'?
>
> Let's say, we unmashall <BooleanTypeTag>turkey</ BooleanTypeTag>, the
> value of the field is set to 'true'.
>
> In both cases, we would expect Jaxb2 to set the value of the field to
> 'null' as the type doesn't match.
Kohsuke Kawaguchi wrote:
Generally speaking, unless you turn the validation on, the JAXB RI
itself won't enforce the datatype constraints. So just like
java.lang.Boolean.parseBoolean() takes everything except "true" as
false, the JAXB RI also recognizes things other than
"true"/"false"/"0"/"1".
>>> Even with the validations turned off, JAXB is throwing error events
for Date and other data types. Is it because of setting
ValidationEventHandler?
It's not clear to me if the behavior you proposed is better, too. For
example, I can argue that the fact that <BooleanTypeTag> was present
does indicate that the document is trying to set some value, and in that
sense true or false is better than null as it at least captures the
presence of some value.
>>> I would have to disagree with your argument. Sending some unknown
value may not mean that, we should present the user with wrong
information to let the user know.
Take for example <LoanRequired> is of type xs:Boolean.
Let's say we got value of 'yes', which is not a valid Boolean type
value. Unmarshalling this value to 'false', application would process as
if value 'false' is received and error will never be caught. This will
alter the behavior of the whole application? Wouldn't you agree?
Instead, if unmarshalled to 'null', application rules may catch this
condition.
Specifically considering how JAXB works in case of 'xs:date',
'xs:decimal' & 'xs:string -enumerated' type fields (unmarshalls value to
'null' if unrecognized value is encountered), and for all practical
purposes, it would be better to unmarshall the value to 'null' and throw
validation error event.
> 2) Is there a document that describes how unmarshalling will be
> done when values doesn't math type?
No. Those aren't really committed behaviors either. The spec doesn't
really say what to do when invalid values are encountered.
If you'd like to catch those errors, use validation.
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com