Dozer is not able to map generic collection properties without hint or setter

659 views
Skip to first unread message

Denis Sokol

unread,
Mar 25, 2013, 5:37:26 AM3/25/13
to dozer-...@googlegroups.com

I think the code below will be self-explaining. I can make it work in two possible ways:

  • Provide setters to CollectionHolderB and CollectionHolderA classes. OR
  • Uncommenting the hint method.

I am not able to change CollectionHolderB and CollectionHolderA classes. I am looking for a way around hinting all available collections within my model. Any suggestions?

public class CollectionHolderA {
   private List<String> values = new ArrayList<String>();
   public List<String> getValues() {
      return values;
   }
}

public class CollectionHolderB {
   private List<Integer> values = new ArrayList<Integer>();
   public List<Integer> getValues() {
      return values;
   }
}



@Test
public void publicTestCollectionMappingWithoutSetters() {
    DozerBeanMapper mapper = new DozerBeanMapper();

    // Works only if uncommented
    // mapper.addMapping(new BeanMappingBuilder() {
    //
    // @Override
    // protected void configure() {
    // mapping(CollectionHolderB.class, CollectionHolderA.class)
    //    .fields("values", "values",
    //          FieldsMappingOptions.hintA(Integer.class),
    //          FieldsMappingOptions.hintB(String.class));
    //          }

    CollectionHolderB objB = new CollectionHolderB();
    objB.getValues().add(new Integer(0));
    objB.getValues().add(new Integer(1));
    CollectionHolderA objA = mapper.map(objB, CollectionHolderA.class);

    Assert.assertArrayEquals(new String[] { "0", "1" }, (String[]) objA.getValues().toArray(new String[objA.getValues().size()]));

}
CollectionHolderA.java
CollectionHolderB.java
ParametrizedCollectionsMappingTest.java

Denis Sokol

unread,
Mar 25, 2013, 5:43:07 AM3/25/13
to dozer-...@googlegroups.com

Denis Sokol

unread,
Mar 27, 2013, 9:14:07 AM3/27/13
to dozer-...@googlegroups.com
Hey! Can smb help with it?

Dmitry Buzdin

unread,
Mar 28, 2013, 4:28:42 PM3/28/13
to dozer-...@googlegroups.com
I remember fixing something like that in the past, but if you are saying it does not work and it is the last version of Dozer I believe this is simply a bug (missing feature).

Your test should help to identify the cause. Please create an issue in GitHub with this test case and, ideally, patch to solve it.

Regards,
Dmitry

среда, 27 марта 2013 г., 15:14:07 UTC+2 пользователь Denis Sokol написал:

Denis Sokol

unread,
Mar 29, 2013, 4:56:53 AM3/29/13
to dozer-...@googlegroups.com
Hello Dmitry! 

I am using Dozer 5.4.0.

I booked an issue: https://github.com/DozerMapper/dozer/issues/86, but I don't have patch for it. 

I wonder if there is a fast way around it?
Reply all
Reply to author
Forward
0 new messages