@Test public void copyArrayObject() { Student student1 = new Student("zhang3", 20, new Teacher("li4"), ListUtil.newArrayList("chinese", "english")); Student student2 = new Student("zhang4", 30, new Teacher("li5"), ListUtil.newArrayList("chinese2", "english4")); Student student3 = new Student("zhang5", 40, new Teacher("li6"), ListUtil.newArrayList("chinese3", "english5")); Student[] studentList = new Student[] { student1, student2, student3 }; StudentVO[] studentVoList = BeanMapper.mapArray(studentList, StudentVO.class); assertThat(studentVoList).hasSize(3); StudentVO studentVo = studentVoList[0]; assertThat(studentVo.name).isEqualTo("zhang3"); assertThat(studentVo.getAge()).isEqualTo(20); assertThat(studentVo.getTeacher().getName()).isEqualTo("li4"); assertThat(studentVo.getCourse()).containsExactly("chinese", "english"); }
public static <S, D> D[] mapArray(final S[] sourceArray, final Class<D> destinationClass) { D[] destinationArray = ArrayUtil.newArray(destinationClass, sourceArray.length); int i = 0; for (S source : sourceArray) { if (source != null) { destinationArray[i] = mapper.map(sourceArray[i], destinationClass); i++; } } return destinationArray; }
BeanMapper { public static <S, D> D[] mapArray(final S[] sourceArray, final Class<D> destinationClass) { D[] destinationArray = ArrayUtil.newArray(destinationClass, sourceArray.length); int i = 0; for (S source : sourceArray) { if (source != null) { destinationArray[i] = mapper.map(sourceArray[i], destinationClass); i++; } } return destinationArray; } }
BeanMapper { public static <S, D> D[] mapArray(final S[] sourceArray, final Class<D> destinationClass) { D[] destinationArray = ArrayUtil.newArray(destinationClass, sourceArray.length); int i = 0; for (S source : sourceArray) { if (source != null) { destinationArray[i] = mapper.map(sourceArray[i], destinationClass); i++; } } return destinationArray; }  }
BeanMapper { public static <S, D> D[] mapArray(final S[] sourceArray, final Class<D> destinationClass) { D[] destinationArray = ArrayUtil.newArray(destinationClass, sourceArray.length); int i = 0; for (S source : sourceArray) { if (source != null) { destinationArray[i] = mapper.map(sourceArray[i], destinationClass); i++; } } return destinationArray; }  static D map(S source, Class<D> destinationClass); static List<D> mapList(Iterable<S> sourceList, Class<D> destinationClass); static D[] mapArray(final S[] sourceArray, final Class<D> destinationClass); }
BeanMapper { public static <S, D> D[] mapArray(final S[] sourceArray, final Class<D> destinationClass) { D[] destinationArray = ArrayUtil.newArray(destinationClass, sourceArray.length); int i = 0; for (S source : sourceArray) { if (source != null) { destinationArray[i] = mapper.map(sourceArray[i], destinationClass); i++; } } return destinationArray; }  static D map(S source, Class<D> destinationClass); static List<D> mapList(Iterable<S> sourceList, Class<D> destinationClass); static D[] mapArray(final S[] sourceArray, final Class<D> destinationClass);  }