@SuppressWarnings("unchecked") public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception { if (source == null) { return null; } Class<?> collectionImplClass = getCollectionImplClass(targetClass); Constructor<?> constructor = collectionImplClass.getConstructor(); Collection<Object> collection = (Collection<Object>) constructor.newInstance(); ConversionExecutor converter = getArrayElementConverter(source, targetClass); int length = Array.getLength(source); for (int i = 0; i < length; i++) { Object value = Array.get(source, i); if (converter != null) { value = converter.execute(value); } collection.add(value); } return collection; }
public Object convertSourceToTargetClass(Object source, Class targetClass) throws Exception { if (source == null) { return null; } Class collectionImplClass = getCollectionImplClass(targetClass); Constructor constructor = collectionImplClass.getConstructor(null); Collection collection = (Collection) constructor.newInstance(null); ConversionExecutor converter = getElementConverter(source, targetClass); int length = Array.getLength(source); for (int i = 0; i < length; i++) { Object value = Array.get(source, i); if (converter != null) { value = converter.execute(value); } collection.add(value); } return collection; }
@SuppressWarnings("unchecked") public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception { if (source == null) { return null; } Class<?> collectionImplClass = getCollectionImplClass(targetClass); Constructor<?> constructor = collectionImplClass.getConstructor(); Collection<Object> collection = (Collection<Object>) constructor.newInstance(); ConversionExecutor converter = getArrayElementConverter(source, targetClass); int length = Array.getLength(source); for (int i = 0; i < length; i++) { Object value = Array.get(source, i); if (converter != null) { value = converter.execute(value); } collection.add(value); } return collection; }