#99 Prob w/ map-get-method and date-format (patch included)

closed
None
5
2007-07-15
2007-06-08
No

Hi,
Again I found something. I would call it a bug, because it doesnt work with my usecase:
http://sourceforge.net/forum/forum.php?thread_id=1721912&forum_id=452530

I think the whole map-get-method-thing isnt meant to be the way I want. Today I wanted to use the nice date-format attribute with a german date string:

<a map-get-method="getColByName" key="fieldNameA" date-format="dd.MM.yyyy">this</a>

This didnt work, because all the nice things which were added to dozer like the date-format attribute were thought for the simple way of getting a value from the source object. In combination with map-get-method it is simply ignored.
As I browsed through the code i noticed that all the different features are not developed in a hierarchical way. There must be something like getRealValueFromSourceObject() and something like processRealValue() which must be called afterwards (in every case). Unfortunatly the value-getting and the value-processing tasks are mixed, so I might get some more problems in the future. :(

So again here is my patch, hope someone will benefit from this.
with Dozer version 3.4,
in MappingProcessor.java,
in function mapOrRecurseObject,
at line 435,
I added:
//instead of directly returning the result,
//check if next condition will be true.
//If it is, the result will be the source
//which will get wrapped through the //primitiveOrWrapperConverter
Object result = mapCustomMapToProperty(sourceFieldValue, sourceFieldClass, fieldMap, destObj, destFieldType);
if (!MappingUtils.isPrimitiveOrWrapper(sourceFieldClass) && !MappingUtils.isPrimitiveOrWrapper(destFieldType))
return result;
else
sourceFieldValue = result;

One thing to say: I still appreciate all the work that has been done and im still happy with dozer. But you may should think about a refactoring. Ok, I dont have the time to do that either :)

Thanks so far!
Markus

Discussion

  • Matt Tierney

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

    Matt Tierney - 2007-06-09

    Logged In: YES
    user_id=1236069
    Originator: NO

    Thanks for taking the time to submit this. I agree with you that there are still some warts that should be refactored out. I think you are running into one of those areas. A generic mapping framework is very difficult from a coding perspective because it is so recursive in nature and has to handle what seems like an endless # of possible use cases. We are always agressively refactoring known pain points and will continue to do so.

     
  • Matt Tierney

    Matt Tierney - 2007-07-08
    • status: open --> pending
     
  • Matt Tierney

    Matt Tierney - 2007-07-08

    Logged In: YES
    user_id=1236069
    Originator: NO

    This has been resolved. I just finished up the large refactoring of map backed property support and this was resolved with that effort. I added a unit test to verify that this use case now works. The unit test is MapTypeTest.testDateFormat_CustomMapType() and the dozer mapping looks like......

    <mapping>
    <class-a>net.sf.dozer.util.mapping.vo.map.CustomMap</class-a>
    <class-b>net.sf.dozer.util.mapping.vo.SimpleObj</class-b>
    <field>
    <a map-get-method="getValue" map-set-method="putValue" key="fieldA" date-format="MM/dd/yyyy">this</a>
    <b>field5</b>
    <a-hint>java.lang.String</a-hint>
    </field>
    </mapping>

     
  • 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