Menu

#374 invalid copy of array of primitives

Dozer v5.3.2
open
nobody
5
2012-05-22
2012-05-22
fr3drex
No

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);
}

Discussion

  • fr3drex

    fr3drex - 2012-05-22
    • milestone: --> Dozer v5.3.2
     
  • Karsten Ohme

    Karsten Ohme - 2012-08-04

    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>

     

Log in to post a comment.