Custom Mappers

  • Richard Lemesle

    Richard Lemesle - 2005-09-08


    I'm trying to use custom mappers and it doesn't work as I expected.

    I have the following classes :

    class A {

    T1 attribute;

    class B {
    T2 attribute;

    A is mapped to B with the following mapping :


    And T1 is mapped to T2 with a custom mapper.

    I create a instance of A and map it to B.Class so the method convert(Class destination, Object source) of the custom mapper is called with destination=T2.class and source=the instance of T1

    That's ok.

    I change the value of the attribute of the instance of A.

    Then, I take the instance of B returned by this first mapping and map it back to the instance of A. The SAME convert method of the custom mapper is called with destination=T1.class and source=the instance of T2.

    So, the convert method with a source object and a destination object is never called ?!?!

    Is it a bug ?

    How can I use an existing value in the destiontion attribute ??

    An other problem is that my classes T1 and T2 represents immutable objects (as String for example) and can't be changed so the API

    void convert(Object destination, Object source) is useless since destination is a new object.

    a correct API would be :

    Object convert (Object destination, Object source) where the destination parameter is the value of the destination BEFORE conversion and the returned value of the convert method is the value of the destination AFTER conversion.

    Am I right ?


    • Richard Lemesle

      Richard Lemesle - 2005-09-09


      Week-end is near (it's already arrived for me since it's 18h45 here)

      Can someone confirm that this is a bug (or explain if it isn't) ?

      Good Week-end for you !

      This is my last post for this week ;-)


    • Ben Sullins

      Ben Sullins - 2005-09-09

      Well, there might be a bidirectional bug there, but the converter should recognize the source and destination swap.  Also, only the converter will be called for the object, not both generic mapping and custom converter mapping.
      (I think, will double check that)


      • Franz Garsombke

        Franz Garsombke - 2005-09-09

        We will reproduce this and let you know either way. I need to dig into it a bit.



      • Richard Lemesle

        Richard Lemesle - 2005-09-09

        I don't use a generic mapping AND a custom one here.

        I use a generic mapping between A and B and a custom mapping between T1 and T2 (representing enums with the enum standard pattern)
        A has a attribute of type T1 and B has an attribute of type T2.

        My converter can recognize the source and destination swap but on the two methods defined in it (convert(class,object) and convert(object, object)) only the first one is called...

        And as I try to explain in my first post, i make a first mapping between A and B and then map back B to A so A as already an attribute of type T1 and I though the second method of the converted would be called....

    • Richard Lemesle

      Richard Lemesle - 2005-09-15

      Great !

      I just saw the 1.5.2 has been released with many things we wanted !!

      We will test all that !

      Any news about the custom mapper questions submitted here ?

      As always, Thanks a lot !


      • Franz Garsombke

        Franz Garsombke - 2005-09-15

        Hey Richard -

        Matt is going to answer that one for ya :)


      • Matt Tierney

        Matt Tierney - 2005-09-16

        Let me create a unit test for your use case and try to reproduce what you are seeing.  After I reproduce the issue I will work on the fix.  Hopefully I can get you a response to this within the next week or so.  Thanks for your post and great feedback!  Have a good one.  Cheers

    • Franz Garsombke

      Franz Garsombke - 2005-09-16

      I have rewritten the custom mapping piece and will release it this weekend as 1.5.3. The documentation will be updated as to using it. It is a much cleaner interface and will allow you to do exactly what you need.



      • Richard Lemesle

        Richard Lemesle - 2005-09-17

        Great !

        I will test that next week.

        I took a look to the custom mapper documentation and it's clear and seems to work now in a way we can do all we want with custom mappers ;-)




Log in to post a comment.

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

Sign up for the SourceForge newsletter:

No, thanks