Class TypeConverters
- java.lang.Object
-
- org.apache.logging.log4j.core.config.plugins.convert.TypeConverters
-
public final class TypeConverters extends Object
Collection of basic TypeConverter implementations. May be used to register additional TypeConverters or find registered TypeConverters.- Since:
- 2.1 Moved to the
convert
package.
-
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description static String
CATEGORY
ThePlugin Category
to use forTypeConverter
plugins.
-
Constructor Summary
Constructors Constructor Description TypeConverters()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
convert(String s, Class<? extends T> clazz, Object defaultValue)
Converts a String to a given class if a TypeConverter is available for that class.
-
-
-
Field Detail
-
CATEGORY
public static final String CATEGORY
ThePlugin Category
to use forTypeConverter
plugins.- Since:
- 2.1
- See Also:
- Constant Field Values
-
-
Method Detail
-
convert
public static <T> T convert(String s, Class<? extends T> clazz, Object defaultValue)
Converts a String to a given class if a TypeConverter is available for that class. Falls back to the provided default value if the conversion is unsuccessful. However, if the default value is also invalid, thennull
is returned (along with a nasty status log message).- Parameters:
s
- the string to convertclazz
- the class to try to convert the string todefaultValue
- the fallback object to use if the conversion is unsuccessful- Returns:
- the converted object which may be
null
if the string is invalid for the given type - Throws:
NullPointerException
- ifclazz
isnull
IllegalArgumentException
- if no TypeConverter exists for the given class
-
-