public Object convertSourceToTargetClass(Object source, Class<?> targetClass) { if (source == null) { return null; } Class<?> sourceComponentType = source.getClass().getComponentType(); Class<?> targetComponentType = targetClass.getComponentType(); int length = Array.getLength(source); Object targetArray = Array.newInstance(targetComponentType, length); ConversionExecutor converter = getElementConverter(sourceComponentType, targetComponentType); for (int i = 0; i < length; i++) { Object value = Array.get(source, i); Array.set(targetArray, i, converter.execute(value)); } return targetArray; }
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) { if (source == null) { return null; } Class<?> sourceComponentType = source.getClass().getComponentType(); Class<?> targetComponentType = targetClass.getComponentType(); int length = Array.getLength(source); Object targetArray = Array.newInstance(targetComponentType, length); ConversionExecutor converter = getElementConverter(sourceComponentType, targetComponentType); for (int i = 0; i < length; i++) { Object value = Array.get(source, i); Array.set(targetArray, i, converter.execute(value)); } return targetArray; }