Converting a map backed object.

Help
2005-10-25
2013-05-02
  • Joel Wickard

    Joel Wickard - 2005-10-25

    Hello,

    I just started experimenting with Dozer within the last day, and the first thing I have to convert is turning out to be a little more complex then a standard java bean to java bean mapping.

    I have a standard Pojo for class A, but class B is a struts DynaActionForm - which has it's property name/values backed by a map and only exposes a few  overloaded get(), set() calls to wrap the map. 

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mappings PUBLIC "-//DOZER//DTD MAPPINGS//EN"
        "http://dozer.sourceforge.net/dtd/dozerbeanmapping.dtd">
    <mappings>         
        <mapping type="bi-directional">
            <classA>com.my.sweet.pojos.BananaPhone</classA>
            <classB>org.apache.struts.action.DynaActionForm</classB>
            <field>
                <A>uuid</A>
                <B>id</B>
            </field>
        </mapping> 
    </mappings>

    Currently when I attempt to map two properties I get this error:

    net.sf.dozer.util.mapping.MappingException: net.sf.dozer.util.mapping.MappingException: Unable to determine read method for field: id class: class org.apache.struts.action.DynaActionForm

    which would somewhat make sense that it would't necessarily be able to find the values if it was attempting to use reflection.

    So basically what I'm wondering, is:
    1)Does dozer support a map backed object out-of-the-box and I just misconfigured my mapping?
    -or-
    2)Am I going to have to write a custom converter for map backed properties.

    Any pointers would be great.

    Thank you.

     
    • Ben Sullins

      Ben Sullins - 2005-10-25

      you are correct, Dozer is looking for javabean properties and not finding any.  Struts, as you know, is an extremely popular framework so we should look at mapping to this type of object.  I will look into this, but in the meantime, I think you will need a custom converter.  I have not used that Struts class before, so I will go look at it now to see if there is something else you can do.

      thanks for trying out dozer.

      -ben

       
      • Shailu

        Shailu - 2006-03-21

        As per the examples given at following page:
        http://dozer.sourceforge.net/documentation/mapbackedproperty.html

        I am trying to copy all the properties of my source Object in to a java.util.Map. My source object also has a Map property. Dozer is choking while trying to convert all the properties of my source object. I got the following error:
        net.sf.dozer.util.mapping.MappingException: No method found for class:class java.util.HashMap and method name:null
            at net.sf.dozer.util.mapping.util.MappingUtils.getMethod(MappingUtils.java:689)
            at net.sf.dozer.util.mapping.MappingProcessor.mapClassLevelMap(MappingProcessor.java:500)
            at net.sf.dozer.util.mapping.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:459)
            at net.sf.dozer.util.mapping.MappingProcessor.mapFromFieldMap(MappingProcessor.java:306)
            at net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:281)
            at net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:136)
            at net.sf.dozer.util.mapping.DozerBeanMapper.map(DozerBeanMapper.java:70)
            at com.shal.dozertest.DozerTest.main(DozerTest.java:58)
        Exception in thread "main"

         
    • Joel Wickard

      Joel Wickard - 2005-10-25

      I've since tried to modify my original attempt by trying to map the Map properties instead of the DynaFormBean itself, i.e.:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE mappings PUBLIC "-//DOZER//DTD MAPPINGS//EN"
      "http://dozer.sourceforge.net/dtd/dozerbeanmapping.dtd";>
      <mappings> 
      <mapping type="bi-directional"> 
      <classA>com.my.sweet.pojos.BananaPhone</classA>
      <classB>org.apache.struts.action.DynaActionForm</classB>
      <field-deep-copy>
      <A>uuid</A>
      <B>map.id</B>
      </field-deep-copy>
      </mapping> 
      </mappings>

      there is a getMap() getter and setMap()  setter for DynaActionForm bean, but this attempt still choked when it recieved the actual Map and tried to look for the id property.

       
      • Franz Garsombke

        Franz Garsombke - 2005-10-25

        This seems like a valid use case. We will try to add this functionality for the 1.5.6 release this Friday.

        Thanks for looking.

        Franz

         
    • Joel Wickard

      Joel Wickard - 2005-11-04

      Did this make it in to 1.5.6?  I downloaded it, tried the basic example above, and this time I think I got a new error message.

       
      • Franz Garsombke

        Franz Garsombke - 2005-11-04

        Joel -

        We did not have time to build this into 1.5.6. It is a little harder problem than we thought and I want to allow enough time for covering all of the use cases. We are having a design meeting on Monday and this will definitely be in the 1.5.7 release. I am shooting for a week from today (Nov. 11) for the implementation and release of that.

        I think dozer has a huge gap in converting to map backed objects so we definitely want to put this functionality in.

        Thanks for asking.

        Franz

         
    • Joel Wickard

      Joel Wickard - 2005-11-04

      You guys are the most helpful developers of any OS project I have seen.  Maybe OS developers don't get jaded until the 2.x release typically. </endjoke>

       
      • Franz Garsombke

        Franz Garsombke - 2005-11-04

        LOL.

        Who said anything about a 2.0 release? </endjoke>

        Franz

         
    • Franz Garsombke

      Franz Garsombke - 2005-11-15

      Please check out the 1.5.7 release and let me know if this solves your problem.

      thanks,

      franz

       

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks