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
convertpackage.
-
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description static StringCATEGORYThePlugin Categoryto use forTypeConverterplugins.
-
Constructor Summary
Constructors Constructor Description TypeConverters()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tconvert(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 Categoryto use forTypeConverterplugins.- 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, thennullis 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
nullif the string is invalid for the given type - Throws:
NullPointerException- ifclazzisnullIllegalArgumentException- if no TypeConverter exists for the given class
-
-