Package com.norconex.commons.lang.convert

# Class GenericConverter

java.lang.Object
com.norconex.commons.lang.convert.GenericConverter

All Implemented Interfaces:
  `Converter`

public final class GenericConverter extends Object implements Converter

Converts strings to objects and objects to strings. Supported object types are guaranteed to be convertible both ways if converted by this class.

Can only be initialized at construction time or the default instance can be obtained statically.

Converted string values are NOT locale-specific. This class favors consistency over format and string values are not always appropriate for human-consumption.

Default instance has converters for the following types:

- `BigDecimal`
- `BigInteger`
- `Boolean`/boolean
- `Byte`/byte
- `Character`/char
- `Charset`
- `ContentType`
- `Date`
- `Dimension`
- `Double`/double
- `Duration`
- `Enum`
- `File`
- `Float`/float
- `Instant`
- `Integer`/int
- `LocalDateTime`
- `Locale`
- `Long`/long
- `Path`
- `Pattern`
- `Short`/short
- `URL`
- `ZonedDateTime`
- `ZoneId`

By default `ConverterException` is thrown when conversion fails.

Since:
  3.0.0 (renamed from 2.x "Converter")
See Also:
  - `ConverterException`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GenericConverter(Map<Class<?>,Converter> converters)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `convert(Object object)`
  `static String`
  `convert(Object object, String defaultValue)`
  `static <T> T`
  `convert(String value, Class<T> type)`
  `static <T> T`
  `convert(String value, Class<T> type, T defaultValue)`
  `static List<String>`
  `convert(List<Object> objects)`
  `static <T> List<T>`
  `convert(List<String> values, Class<T> type)`
  `static GenericConverter`
  `defaultInstance()`
  `Converter`
  `getConverter(Class<?> type)`
  `Map<Class<?>,Converter>`
  `getConverters()`
  `boolean`
  `isConvertible(Class<?> type)`
  `String`
  `toString(Object object)`
  `String`
  `toString(Object object, String defaultValue)`
  `List<String>`
  `toString(List<?> objects)`
  `<T> T`
  `toType(String value, Class<T> type)`
  `<T> T`
  `toType(String value, Class<T> type, T defaultValue)`
  `<T> List<T>`
  `toType(List<String> values, Class<T> type)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### GenericConverter

    public GenericConverter(Map<Class<?>,Converter> converters)

- ## Method Details

  - ### defaultInstance

    public static GenericConverter defaultInstance()

  - ### getConverters

    public Map<Class<?>,Converter> getConverters()

  - ### convert

    public static <T> List<T> convert(List<String> values, Class<T> type)

  - ### convert

    public static <T> T convert(String value, Class<T> type)

  - ### convert

    public static <T> T convert(String value, Class<T> type, T defaultValue)

  - ### convert

    public static List<String> convert(List<Object> objects)

  - ### convert

    public static String convert(Object object)

  - ### convert

    public static String convert(Object object, String defaultValue)

  - ### toType

    public <T> List<T> toType(List<String> values, Class<T> type)

  - ### toType

    public <T> T toType(String value, Class<T> type)
    Specified by:
      `toType` in interface `Converter`

  - ### toType

    public <T> T toType(String value, Class<T> type, T defaultValue)
    Specified by:
      `toType` in interface `Converter`

  - ### toString

    public List<String> toString(List<?> objects)

  - ### toString

    public String toString(Object object)
    Specified by:
      `toString` in interface `Converter`

  - ### toString

    public String toString(Object object, String defaultValue)
    Specified by:
      `toString` in interface `Converter`

  - ### isConvertible

    public boolean isConvertible(Class<?> type)

  - ### getConverter

    public Converter getConverter(Class<?> type)