replaced custom asList method with Arrays.asList(ObjectUtils.toObjectArray(...))
This commit is contained in:
parent
cc0bd730eb
commit
9400fb3e78
|
|
@ -16,10 +16,11 @@
|
|||
|
||||
package org.springframework.core.convert.support;
|
||||
|
||||
import static org.springframework.core.convert.support.ConversionUtils.asList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Converts from a source array to a target array type.
|
||||
|
|
@ -40,7 +41,7 @@ final class ArrayToArrayConverter implements GenericConverter {
|
|||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.helperConverter.convert(asList(source), sourceType, targetType);
|
||||
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
|
||||
package org.springframework.core.convert.support;
|
||||
|
||||
import static org.springframework.core.convert.support.ConversionUtils.asList;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Converts from an array to a Map.
|
||||
|
|
@ -42,7 +42,7 @@ final class ArrayToMapConverter implements GenericConverter {
|
|||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.helperConverter.convert(asList(source), sourceType, targetType);
|
||||
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
|
||||
package org.springframework.core.convert.support;
|
||||
|
||||
import static org.springframework.core.convert.support.ConversionUtils.asList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Converts from an array to a single Object.
|
||||
|
|
@ -36,11 +37,11 @@ final class ArrayToObjectConverter implements GenericConverter {
|
|||
}
|
||||
|
||||
public Class<?>[][] getConvertibleTypes() {
|
||||
return new Class<?>[][] { { Object[].class, Object.class } };
|
||||
return new Class<?>[][] {{Object[].class, Object.class}};
|
||||
}
|
||||
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
return this.helperConverter.convert(asList(source), sourceType, targetType);
|
||||
return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,29 +13,30 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.convert.support;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.RandomAccess;
|
||||
|
||||
import org.springframework.core.convert.ConversionFailedException;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
|
||||
final class ConversionUtils {
|
||||
/**
|
||||
* Internal utilities for the conversion package.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @since 3.0
|
||||
*/
|
||||
abstract class ConversionUtils {
|
||||
|
||||
private ConversionUtils() {
|
||||
}
|
||||
|
||||
public static Object invokeConverter(GenericConverter converter, Object source, TypeDescriptor sourceType,
|
||||
TypeDescriptor targetType) {
|
||||
try {
|
||||
return converter.convert(source, sourceType, targetType);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new ConversionFailedException(sourceType, targetType, source, ex);
|
||||
}
|
||||
}
|
||||
|
|
@ -69,26 +70,4 @@ final class ConversionUtils {
|
|||
return new TypeDescriptor[] { TypeDescriptor.valueOf(keyType), TypeDescriptor.valueOf(valueType) };
|
||||
}
|
||||
|
||||
public static List<?> asList(Object array) {
|
||||
return array != null ? new ArrayList(array) : null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class ArrayList extends AbstractList<Object> implements RandomAccess, java.io.Serializable {
|
||||
|
||||
private Object array;
|
||||
|
||||
ArrayList(Object array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return Array.getLength(array);
|
||||
}
|
||||
|
||||
public Object get(int index) {
|
||||
return Array.get(array, index);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue