public final class Converter extends Object implements IConverter
Converts strings to objects and objects to strings. Supported object types are guaranteed to be convertibles 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:
Byte
/byteShort
/shortInteger
/intFloat
/floatLong
/longDouble
/doubleBigInteger
BigDecimal
Boolean
/booleanCharacter
/charFile
Path
Date
LocalDateTime
ZonedDateTime
Instant
Locale
Enum
Dimension
Duration
ContentType
Charset
URL
By default ConverterException
is thrown when conversion fails.
ConverterException
Constructor and Description |
---|
Converter(Map<Class<?>,IConverter> converters) |
Modifier and Type | Method and Description |
---|---|
static List<String> |
convert(List<Object> objects) |
static <T> List<T> |
convert(List<String> values,
Class<T> type) |
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 Converter |
defaultInstance() |
IConverter |
getConverter(Class<?> type) |
Map<Class<?>,IConverter> |
getConverters() |
boolean |
isConvertible(Class<?> type) |
List<String> |
toString(List<?> objects) |
String |
toString(Object object) |
String |
toString(Object object,
String defaultValue) |
<T> List<T> |
toType(List<String> values,
Class<T> type) |
<T> T |
toType(String value,
Class<T> type) |
<T> T |
toType(String value,
Class<T> type,
T defaultValue) |
public Converter(Map<Class<?>,IConverter> converters)
public static Converter defaultInstance()
public Map<Class<?>,IConverter> getConverters()
public <T> T toType(String value, Class<T> type)
toType
in interface IConverter
public <T> T toType(String value, Class<T> type, T defaultValue)
toType
in interface IConverter
public String toString(Object object)
toString
in interface IConverter
public String toString(Object object, String defaultValue)
toString
in interface IConverter
public boolean isConvertible(Class<?> type)
public IConverter getConverter(Class<?> type)
Copyright © 2008–2023 Norconex Inc.. All rights reserved.