Class ArrayConverter<T>

java.lang.Object
jodd.typeconverter.impl.ArrayConverter<T>
All Implemented Interfaces:
TypeConverter<T[]>
Direct Known Subclasses:
ClassArrayConverter, StringArrayConverter

public class ArrayConverter<T> extends 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 Details

    • NUMBER_DELIMITERS

      public static final char[] NUMBER_DELIMITERS
    • typeConverterManager

      protected final TypeConverterManager typeConverterManager
    • targetComponentType

      protected final Class<T> targetComponentType
  • Constructor Details

  • Method Details

    • convert

      public T[] convert(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(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(Object value)
      Creates an array with single element.
    • convertValueToArray

      protected T[] convertValueToArray(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 String[] convertStringToArray(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(Object value)
      Converts array value to array.
    • convertPrimitiveArrayToArray

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