Class DefaultConverter

java.lang.Object
net.minidev.asm.DefaultConverter

public class DefaultConverter extends Object
Provides utility methods to convert objects to different primitive types and their wrapper classes. It supports conversion from Number instances and String representations of numbers to their corresponding primitive types or wrapper classes. Conversion from types that are not supported will result in a ConvertException.
  • Constructor Details

    • DefaultConverter

      public DefaultConverter()
      Default constructor
  • Method Details

    • convertToint

      public static int convertToint(Object obj)
      Converts the given object to an int.
      Parameters:
      obj - the object to convert
      Returns:
      the converted int value, or 0 if the object is null
      Throws:
      ConvertException - if the object cannot be converted to an int
    • convertToInt

      public static Integer convertToInt(Object obj)
      Converts the given object to an Integer.
      Parameters:
      obj - the object to convert
      Returns:
      the converted Integer, or null if the object is null
      Throws:
      ConvertException - if the object cannot be converted to an Integer
    • convertToshort

      public static short convertToshort(Object obj)
      Converts the given object to a short.
      Parameters:
      obj - the object to convert
      Returns:
      the converted short value, or 0 if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a short
    • convertToShort

      public static Short convertToShort(Object obj)
      Converts the given object to a short.
      Parameters:
      obj - the object to convert
      Returns:
      the converted short value, or 0 if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a short
    • convertTolong

      public static long convertTolong(Object obj)
      Converts the given object to a long.
      Parameters:
      obj - the object to convert
      Returns:
      the converted long value, or 0 if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a long
    • convertToLong

      public static Long convertToLong(Object obj)
      Converts the given object to a Long.
      Parameters:
      obj - the object to convert
      Returns:
      the converted Long, or null if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a Long
    • convertTobyte

      public static byte convertTobyte(Object obj)
      Converts the given object to a byte.
      Parameters:
      obj - the object to convert
      Returns:
      the converted byte value, or 0 if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a byte
    • convertToByte

      public static Byte convertToByte(Object obj)
      Converts the given object to a Byte.
      Parameters:
      obj - the object to convert
      Returns:
      the converted Byte, or null if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a Byte
    • convertTofloat

      public static float convertTofloat(Object obj)
      Converts the given object to a float.
      Parameters:
      obj - the object to convert
      Returns:
      the converted float value, or 0f if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a float
    • convertToFloat

      public static Float convertToFloat(Object obj)
      Converts the given object to a Byte.
      Parameters:
      obj - the object to convert
      Returns:
      the converted Byte, or null if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a Byte
    • convertTodouble

      public static double convertTodouble(Object obj)
      Converts the given object to a double.
      Parameters:
      obj - the object to convert
      Returns:
      the converted double value, or 0.0 if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a double
    • convertToDouble

      public static Double convertToDouble(Object obj)
      Converts the given object to a Double.
      Parameters:
      obj - the object to convert
      Returns:
      the converted Double, or null if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a Double
    • convertTochar

      public static char convertTochar(Object obj)
      Converts the given object to a char.
      Parameters:
      obj - the object to convert
      Returns:
      the converted char value, or a space character if the object is null or the string is empty
      Throws:
      ConvertException - if the object cannot be converted to a char
    • convertToChar

      public static Character convertToChar(Object obj)
      Converts the given object to a Character.
      Parameters:
      obj - the object to convert
      Returns:
      the converted Character, or null if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a Character
    • convertTobool

      public static boolean convertTobool(Object obj)
      Converts the given object to a boolean.
      Parameters:
      obj - the object to convert
      Returns:
      the converted boolean value, false if the object is null or represents the numeric value 0
      Throws:
      ConvertException - if the object cannot be converted to a boolean
    • convertToBool

      public static Boolean convertToBool(Object obj)
      Converts the given object to a Boolean.
      Parameters:
      obj - the object to convert
      Returns:
      the converted Boolean, or null if the object is null
      Throws:
      ConvertException - if the object cannot be converted to a Boolean