#108 Custom converter called on null source field

closed
None
5
2007-12-16
2007-09-10
Stanford
No

I am not sure if this is a bug or not, but it bit me and I had to modify my custom converter to work around it. Here is the issue:

1) I have a field in the source class that has a custom converter

2) The field may be null, so I set map-null to false

3) My mapping would fail because the custom converter was called with a null source object reference

My expectation was that if map-null was false and the source reference was null, the mapping was bypassed, including not calling the custom converter.

I can see where this might not be a bug, since the custom converter could map a default value when the source is null.

I worked around it by modifying my custom converter to return null when the source reference was null. Things worked as expected then, with the setter on the destination object not being called when the source field was null.

Thought I'd bring it to your attention and let you guys decide.

Stan

Discussion

  • Matt Tierney

    Matt Tierney - 2007-09-11

    Logged In: YES
    user_id=1236069
    Originator: NO

    Thanks for the post. Your analysis is correct and currently the map-null is ignored for custom converters. I will take a look at the custom converter docs and make sure that the behavior is documented. There was a feature request awhile ago for adding the functionality to invoke custom converters for null values. I can see arguments both way and I don't feel strongly either way. I think your solution is workable and we can think more about if the map-null should override the default behavior.

    http://sourceforge.net/tracker/index.php?func=detail&aid=1563795&group_id=133517&atid=727368

     
  • Matt Tierney

    Matt Tierney - 2007-12-15
    • assigned_to: nobody --> mhtierney
     
  • Matt Tierney

    Matt Tierney - 2007-12-15

    Logged In: YES
    user_id=1236069
    Originator: NO

    I think you have raised a good point. Right now, the map-null controls whether the destination value is written to the destination value, but as you mentioned the custom converter is still called to determine the destination value. I am going to research adding a check not to call the custom converter when map-null = false and the src value is null

     
  • Matt Tierney

    Matt Tierney - 2007-12-16

    Logged In: YES
    user_id=1236069
    Originator: NO

    fixed and unit tested

     
  • Matt Tierney

    Matt Tierney - 2007-12-16
    • status: open --> pending
     
  • Matt Tierney

    Matt Tierney - 2007-12-16
    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks