#95 Prob w/ map-get-method and CustomConverter (patch included)

closed
None
5
2007-07-15
2007-05-23
No

Hi again,
This time I think i found a bug.

In my previous post: http://sourceforge.net/forum/forum.php?thread_id=1721912&forum_id=452530
I had a problem with mapping map-backed properties (as it finally turns out).
Since then I'm using the solution that Matt found for me and I'm quite happy with that:

<field>
<a map-get-method="getValue" key="fieldA">this</a>
<b>fieldA</b>
</field>

(notice the "this")
But... when I do this together with a custom-converter:

<field custom-converter="MyCustomConverter">
<a map-get-method="getValue" key="fieldA">this</a>
<b>fieldA</b>
</field>

the nice map-get-method/this thing does not work. Within MyCustomConverter I always get the whole
class-a object as the sourceObject argument (due to the "this" in my mapping.xml). The map-get-method is completly ignored.
Don't know whether this is intended. Anyway i patched Dozer to work the way I want to:

with Dozer version 3.4,
in MappingProcessor.java,
in function mapUsingCustomConverter,
at line 1000,
I added:

if (MappingUtils.isCustomMapMethod(fieldMap)) {
String key = fieldMap.getSourceKey();
Method resultMethod = ReflectionUtils.getMethod(srcFieldValue, fieldMap.getSourceField().getMapGetMethod());
srcFieldValue = resultMethod.invoke(srcFieldValue, new Object[] { key });
}

and it works.
Would be nice to see this getting included in Dozer.

Thanks!
Markus

Discussion

  • Matt Tierney

    Matt Tierney - 2007-05-24

    Logged In: YES
    user_id=1236069
    Originator: NO

    Hi Markus,

    Thanks for submitting this bug and the patch. We really appreciate you taking the time to include the code that resolves the issue. I think you found a legitimate bug and it's probably a gap in the existing field custom converter logic. I will take a closer look and we should be able to include this in the next release. Do you happen to already have a simple unit test that reproduces the issue? If so, please submit that as well. If not, I can create one. Thanks again.

     
  • Matt Tierney

    Matt Tierney - 2007-06-05
    • assigned_to: nobody --> mhtierney
     
  • Matt Tierney

    Matt Tierney - 2007-06-10
    • status: open --> pending
     
  • Matt Tierney

    Matt Tierney - 2007-06-10

    Logged In: YES
    user_id=1236069
    Originator: NO

    While investigating this issue, it was quickly apparent that the map-get-method logic was in need of some refactoring. Your patch worked and I understand that was your only option given the current code base, but I decided it was better to take a step back and see what refactoring was needed rather than applying the patch as-is. Submitting the patch was very valuable thought as it prompted me to take a closer look at this code that hasnt been vistited in quite awhile. I completed part 1 of n refactoring and fixed this particular issue, but there is additional work that needs to be done in this area to shore up the feature. I am actively working on this.

     
  • Matt Tierney

    Matt Tierney - 2007-07-15
    • 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