Class TypeConverterUtils
java.lang.Object
com.denodo.configuration.converter.TypeConverterUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TConverts a value of any type to a specific target type.static <T> TConverts a value to a specific target type.static ObjectgetProperty(Object object, String propertyPath) Gets the value of a property from an object.static StringgetPropertyAsString(Object object, String propertyPath) Gets the value of a property as String type from an object.static <T> voidregisterConverter(Class<T> targetType, Function<Object, T> converter) Registers a custom converter for a specific target type.static voidClear the map and register the default converters for primitive types and their wrapper classes.
-
Method Details
-
convert
Converts a value of any type to a specific target type.- Type Parameters:
T- The generic type of the target.- Parameters:
value- The value to convert.targetType- The target type class.- Returns:
- The converted object.
- Throws:
IllegalArgumentException- if the conversion fails or the target type is invalid.
-
convert
Converts a value to a specific target type. If the conversion fails due to an exception, the provided default value is returned.- Type Parameters:
T- The generic type of the target.- Parameters:
value- The value to convert.targetType- The target type class.defaultValue- The default value to return in case of conversion failure.- Returns:
- The converted value or the default value if the conversion fails.
-
getProperty
Gets the value of a property from an object.- Parameters:
object- The object to retrieve the property from.propertyPath- The name of the property to retrieve.- Returns:
- The value of the property, or null if the property does not exist.
- Throws:
IllegalArgumentException- if the object is null or property is null/empty.
-
getPropertyAsString
Gets the value of a property as String type from an object.- Parameters:
object- The object to retrieve the property from.propertyPath- The name of the property to retrieve.- Returns:
- The value of the property, or null if the property does not exist.
- Throws:
IllegalArgumentException- if the object is null or property is null/empty.
-
registerConverter
Registers a custom converter for a specific target type.- Type Parameters:
T- The generic type of the target.- Parameters:
targetType- The target type class.converter- A function that performs the conversion.
-
restoreDefaultCustomConverters
public static void restoreDefaultCustomConverters()Clear the map and register the default converters for primitive types and their wrapper classes.
-