Hi,
I run into issue, after making copy of bean with primitive array, output array is twice long as source array.
Mapping error occurs when :
1. when array field has getters/setters or
2. when property is initialized (like in case of bytes field)
Dozer doesn't throw any exception.
I wrote simple test for that:
public class ArrayWrapper{
byte [] bytes = new byte[3];
int [] ints;
public byte[] getBytes() {
return bytes;
}
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
public int[] getInts() {
return ints;
}
public void setInts(int[] ints) {
this.ints = ints;
}
}
@Test
public void testArrayCopy(){
DozerBeanMapper mapper = new DozerBeanMapper();
ArrayWrapper bean = new ArrayWrapper();
int [] ints = new int[3];
bean.setInts(ints);
ArrayWrapper beanCopy = (ArrayWrapper)mapper.map(bean, ArrayWrapper.class);
assertArrayEquals(ints, beanCopy.ints);
assertArrayEquals(bean.bytes, beanCopy.bytes);
}
I guess, this is a result of Dozers strange default settings. Arrays, Lists and so on are cumulativ copied, i.e. duplicated. In all of my projects this was always wrong. This can be prevented with:
<configuration>
<relationship-type>non-cumulative</relationship-type>
</configuration>