#220 Mapping String collections with "iterate" fails

Dozer v5.3.2
closed-fixed
5
2014-07-26
2009-09-10
No

I have two classes, each with a Set of Strings called "names"
o Class WithAccessors contains getters and setters for the collection
o Class WithoutAccessors contains a getter, no setter, but an addName(String name) method

public class WithAccessors {

private Set<String> names = new HashSet<String>();

public Set<String> getNames() {
return names;
}
public void setNames(Set<String> names) {
this.names = names;
}
}

public class WithoutAccessors {

private Set<String> names = new HashSet<String>();

public void addName(String name) {
names.add(name);
}
public Set<String> getNames() {
return names;
}
}

I provide a mapping as follows:

<mapping>
<class-a>WithAccessors</class-a>
<class-b>WithoutAccessors</class-b>
<field>
<a>names</a>
<b set-method="addName" type="iterate">names</b>
<b-hint>java.lang.String</b-hint>
</field>
</mapping>

The following test fails:
@Test
public void someConversionStringCollectionUsingCustomAccessors() {

WithAccessors with = new WithAccessors();
Set<String> names = new HashSet<String>();
names.add("foo");
with.setNames(names);

WithoutAccessors without = dozerBeanMapper.map(with, WithoutAccessors.class);
Assert.assertEquals(1, without.getNames().size());
Assert.assertEquals("foo", without.getNames().iterator().next());
}

The converted collection is the correct length (1) but contains an empty string.

The value to be set ("foo") is correct up until this point in the org.dozer.MappingProcessor.mapFromIterateMethodFieldMap(Object, Object, Object, FieldMap) method:
value = map(value, fieldMapping.getDestHintContainer().getHint());

At that point the returned value is empty.

It appears as if the method which is invoked tries to map a constant string value to a String object.

Discussion

  • dmitry (lv)

    dmitry (lv) - 2010-06-01
    • assigned_to: nobody --> hedget
     
  • dmitry (lv)

    dmitry (lv) - 2010-12-31

    fixed

     
  • dmitry (lv)

    dmitry (lv) - 2010-12-31
    • milestone: --> Dozer v5.3.2
    • assigned_to: hedget --> buzdin
    • status: open --> closed-fixed
     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks