public final class TypeConverters extends Object
Modifier and Type | Method and Description |
---|---|
static Object |
convert(String s,
Class<?> clazz,
Object defaultValue)
Converts a String to a given class if a TypeConverter is available for that class.
|
static TypeConverter<?> |
findTypeConverter(Class<?> clazz)
Locates a TypeConverter for a specified class.
|
static void |
registerTypeConverter(Class<?> clazz,
TypeConverter<?> converter)
Registers a TypeConverter for a specified class.
|
public static Object convert(String s, Class<?> clazz, Object defaultValue)
null
is returned (along with a nasty status log message).s
- the string to convertclazz
- the class to try to convert the string todefaultValue
- the fallback object to use if the conversion is unsuccessfulnull
if the string is invalid for the given typeNullPointerException
- if clazz
is null
IllegalArgumentException
- if no TypeConverter exists for the given classpublic static TypeConverter<?> findTypeConverter(Class<?> clazz)
clazz
- the class to get a TypeConverter fornull
if none could be foundpublic static void registerTypeConverter(Class<?> clazz, TypeConverter<?> converter)
clazz
- the class to register the TypeConverter forconverter
- the TypeConverter to registerCopyright © 1999-2015 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.