Class TypeConverterUtils

java.lang.Object
com.denodo.configuration.converter.TypeConverterUtils

public class TypeConverterUtils extends Object
  • Method Details

    • convert

      public static <T> T convert(Object value, Class<T> targetType)
      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

      public static <T> T convert(Object value, Class<T> targetType, T defaultValue)
      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

      public static Object getProperty(Object object, String propertyPath)
      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

      public static String getPropertyAsString(Object object, String propertyPath)
      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

      public static <T> void registerConverter(Class<T> targetType, Function<Object,T> converter)
      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.