Class ArrayConverter<T>

  • All Implemented Interfaces:
    TypeConverter<T[]>
    Direct Known Subclasses:
    ClassArrayConverter, StringArrayConverter

    public class ArrayConverter<T>
    extends java.lang.Object
    implements TypeConverter<T[]>
    Converts given object to an array. This converter is specific, as it is not directly registered to a type; but created when needed. Conversion rules:
    • null value is returned as null
    • source non-array value is checked for Collections
    • if non-array element can't be resolved, it is converted to single element array
    • source array is converted to target array, by converting each element
    • Field Detail

      • NUMBER_DELIMITERS

        public static final char[] NUMBER_DELIMITERS
      • targetComponentType

        protected final java.lang.Class<T> targetComponentType
    • Constructor Detail

      • ArrayConverter

        public ArrayConverter​(TypeConverterManager typeConverterManager,
                              java.lang.Class<T> targetComponentType)
    • Method Detail

      • convert

        public T[] convert​(java.lang.Object value)
        Description copied from interface: TypeConverter
        Converts object received as parameter into object of another class. For example, an Integer converter tries to convert given objects into target Integer object. Converters should try all reasonable ways of conversion into target object, depending on target type.
        Specified by:
        convert in interface TypeConverter<T>
        Parameters:
        value - object to convert from
        Returns:
        resulting object converted to target type
      • convertType

        protected T convertType​(java.lang.Object value)
        Converts type using type converter manager.
      • createArray

        protected T[] createArray​(int length)
        Creates new array of target component type. Default implementation uses reflection to create an array of target type. Override it for better performances.
      • convertToSingleElementArray

        protected T[] convertToSingleElementArray​(java.lang.Object value)
        Creates an array with single element.
      • convertValueToArray

        protected T[] convertValueToArray​(java.lang.Object value)
        Converts non-array value to array. Detects various collection types and iterates them to make conversion and to create target array.
      • convertStringToArray

        protected java.lang.String[] convertStringToArray​(java.lang.String value)
        Converts string to array, for the convertValueToArray(Object) method. By default, the string is converted into an array using CsvUtil.
      • convertArrayToArray

        protected T[] convertArrayToArray​(java.lang.Object value)
        Converts array value to array.
      • convertPrimitiveArrayToArray

        protected T[] convertPrimitiveArrayToArray​(java.lang.Object value,
                                                   java.lang.Class primitiveComponentType)
        Converts primitive array to target array.