Hi Johannes,

This behavior was a design decision. The funny thing about design 
decisions is that you make them (or at least I do) without necessarily 
having a full understanding of the downstream implications. When I was 
writing the code, it seemed natural to me to pass a null value to the 
deserializer method if the attribute or element was missing and no 
default was specified, so that the deserializer method could handle this 
case as appropriate. That gives the deserializer method full control 
over the handling, so that a deserializer for a dateTime value, for 
instance, could make the default date/time 2000-01-01T00:00:00 if it 
wanted (rather than null). That seemed to me to be consistent with the 
idea that the deserializer would be responsible for all value conversions.

But this behavior has come as a surprise to at least several users over 
the last couple of years, who have wondered why they're getting 
NullPointerExceptions in trying to handle the values passed to the 
deserializer method. So I've come to the conclusion that although the 
theory I applied in making the original decision may have been good, the 
practical implications have not. I've therefore reversed this in the 
latest code, available as the 1.1.4-SNAPSHOT jars on 
http://jibx.sourceforge.net/maven/jibx/jars/

If you'd like to try out these jars they should have the behavior you're 
expecting, where the deserializer method only gets called if either the 
element/attribute is present or a default value is specified in the binding.

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Johannes Müller wrote:
> JiBX v1.1.3 calls deserialization methods for optional attributes, i.e.
> with a structure like
>
> <structure name="foo">
>   <value style="attribute" usage="optional" name="bar"
>     deserializer="com.foobar.JiBXHelper.deserializeBarEnum"
>     serializer="com.foobar.JiBXHelper.serializeBarEnum" />
> </structure>
>
> the method "com.foobar.JiBXHelper.deserializeBarEnum" gets called during 
> unmarshalling even when the "bar"-attribute does not exist, like with the 
> following XML:
>
> <foo>
> </foo>
>
> This behavior is not what I would expect, because if there is no 
> "bar"-attribute to deserialize, why should its deserialization method be 
> called?
>
> Under
>
> http://www.mail-archive.com/[email protected]/msg00003.html
>
> it is stated that this behavior of JiBX is intended, but there's no 
> explanation given for this intention.
>
> Although the proposed workaround of simply returning null when the method is 
> called with a null parameter, I would like to know what the reason for this 
> behavior is. Why doesn't JiBX just skip the deserialization method calls when 
> the attribute is not given at all?
>
> Thanks,
>
> Johannes Müller
>
>   

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to