public class ArrayToCollection extends java.lang.Object implements TwoWayConverter
List.class
is
specified. Supports type conversion of array elements when a concrete parameterized collection class is provided,
such as IntegerList.class
.
Note that type erasure prevents arbitrary access to generic collection element type information at runtime,
preventing the ability to convert elements for collections declared as properties.
Mainly used internally by ConversionService
implementations.Constructor and Description |
---|
ArrayToCollection(ConversionExecutor elementConverter)
Creates a new array to collection converter.
|
ArrayToCollection(ConversionService conversionService)
Creates a new array to collection converter.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
convertSourceToTargetClass(java.lang.Object source,
java.lang.Class targetClass)
Convert the provided source object argument to an instance of the specified target class.
|
java.lang.Object |
convertTargetToSourceClass(java.lang.Object target,
java.lang.Class sourceClass)
Convert the provided target object argument to an instance of the specified source class.
|
java.lang.Class |
getSourceClass()
The source class this converter can convert from.
|
java.lang.Class |
getTargetClass()
The target class this converter can convert to.
|
public ArrayToCollection(ConversionService conversionService)
conversionService
- the conversion service to use to lookup the converter to apply to array elements added
to the target collectionpublic ArrayToCollection(ConversionExecutor elementConverter)
elementConverter
- A specific converter to use on array elements when adding them to the target collectionpublic java.lang.Class getSourceClass()
Converter
getSourceClass
in interface Converter
public java.lang.Class getTargetClass()
Converter
getTargetClass
in interface Converter
public java.lang.Object convertSourceToTargetClass(java.lang.Object source, java.lang.Class targetClass) throws java.lang.Exception
Converter
convertSourceToTargetClass
in interface Converter
source
- the source object to convert, which must be an instance of Converter.getSourceClass()
targetClass
- the target class to convert the source to, which must be equal to or a specialization of
Converter.getTargetClass()
targetClass
java.lang.Exception
- an exception occurred performing the conversionpublic java.lang.Object convertTargetToSourceClass(java.lang.Object target, java.lang.Class sourceClass) throws java.lang.Exception
TwoWayConverter
convertTargetToSourceClass
in interface TwoWayConverter
target
- the target object to convert, which must be an instance of Converter.getTargetClass()
sourceClass
- the source class to convert the target to, which must be equal to or a specialization of
Converter.getSourceClass()
sourceClass
java.lang.Exception
- an exception occurred performing the conversion