I am able to map array to complex type as specified in one of the answers in this link. However my application contains more than 500 classes and it will be very time consuming to identify and map these one by one. I am trying to build a generic method which would do this conversion. For example , complex type to array can be achieved by using the following methods. I am looking for ways to do the reverse operation -
public <T> T map(Object srcObj, Class<?> destClass, String mapId) {
if (srcObj == null) {
return null;
}
if (srcObj.getClass().isArray()) {
return (T) mapArrayToArray((Object[]) srcObj, destClass);
}
return (T) dozerBeanMapper.map(srcObj, destClass, mapId);
}
private Object mapArrayToArray(Object[] srcArray, Class<?> destClass) {
Class<?> componentType = destClass.getComponentType();
Object resultArray = Array.newInstance(componentType, srcArray.length);
for (int i = 0; i < srcArray.length; i++) {
Object resultItem = this.map(srcArray[i], componentType);
Array.set(resultArray, i, resultItem);
}
return resultArray;
}