[Dozer 5.5.1] Bad non-cumulative orphan removals in Lists
See original GitHub issueUsing dozer 5.5.1 from Maven repository.
Calling dozerBeanMapper.map(stringHolder0, stringHolder1);
. Both argument objects are pre-initialized and are the same Class. Both objects wrap their own instance of List<String> strings;
. Dozer is configured to map the strings
field non-cumulative and to remove-orphans.
When mapping "1", "2"
to "1", "2"
, the result is empty.
When mapping "1", "3"
to "1", "2"
, the result is "3"
.
Are list elements considered orphaned, although they are not? Please see attached unit test for illustration purposes.
org.test.ListHolder - simple string list wrapper
public class ListHolder {
List<String> strings;
public List<String> getStrings() {
return strings;
}
public void setStrings(List<String> strings) {
this.strings = strings;
}
}
Failing unit test for illustration purposes:
public class MapperTest {
DozerBeanMapper dozerBeanMapper;
@Before
public void init() {
dozerBeanMapper = new DozerBeanMapper();
dozerBeanMapper.setMappingFiles(Arrays.asList("dozer-list-mapping.xml"));
}
@Test
public void test00() {
List<String> arrayList0 = new ArrayList<String>();
arrayList0.add("1");
arrayList0.add("2");
ListHolder stringHolder0 = new ListHolder();
stringHolder0.setStrings(arrayList0);
List<String> arrayList1 = new ArrayList<String>();
arrayList1.add("1");
arrayList1.add("2");
ListHolder stringHolder1 = new ListHolder();
stringHolder1.setStrings(arrayList1);
dozerBeanMapper.map(stringHolder0, stringHolder1);
List<String> strings = stringHolder1.getStrings();
// fails - strings is empty
assertEquals(2,strings.size());
assertEquals("1",strings.get(0));
assertEquals("2",strings.get(1));
}
@Test
public void test01() {
List<String> arrayList0 = new ArrayList<String>();
arrayList0.add("1");
arrayList0.add("3");
ListHolder stringHolder0 = new ListHolder();
stringHolder0.setStrings(arrayList0);
List<String> arrayList1 = new ArrayList<String>();
arrayList1.add("1");
arrayList1.add("2");
ListHolder stringHolder1 = new ListHolder();
stringHolder1.setStrings(arrayList1);
dozerBeanMapper.map(stringHolder0, stringHolder1);
List<String> strings = stringHolder1.getStrings();
// fails - strings contains only 1 element -> "3"
assertEquals(2,strings.size());
assertEquals("1",strings.get(0));
assertEquals("2",strings.get(1));
}
}
dozer-list-mapping.xml:
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping map-null="false">
<class-a>org.test.ListHolder</class-a>
<class-b>org.test.ListHolder</class-b>
<field relationship-type="non-cumulative" remove-orphans="true">
<a>strings</a>
<b>strings</b>
</field>
</mapping>
</mappings>
java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
Issue Analytics
- State:
- Created 9 years ago
- Comments:7
Top Results From Across the Web
Release Notes - Dozer
5.5.1 22/04/2014 ... Mapping null values within List to List mapping causes NPE link ... Remove-orphans is not handled when mapping java.util.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Nodoby knows how to fix this yet? This issue is a pretty big problem. - Also: Why the heck is ‘non-cumulative’ and ‘remove-orphans’ not the default globally? I had to bleed my brain with workarounds, I think it would be a great idea to make these changes.
Will this be fixed sometime?
@lihue Could you please provide your workaround?