Class DefaultConverter
java.lang.Object
net.minidev.asm.DefaultConverter
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanconvertTobool(Object obj) Converts the given object to aboolean.static BooleanconvertToBool(Object obj) Converts the given object to aBoolean.static byteconvertTobyte(Object obj) Converts the given object to abyte.static ByteconvertToByte(Object obj) Converts the given object to aByte.static charconvertTochar(Object obj) Converts the given object to achar.static CharacterconvertToChar(Object obj) Converts the given object to aCharacter.static doubleconvertTodouble(Object obj) Converts the given object to adouble.static DoubleconvertToDouble(Object obj) Converts the given object to aDouble.static floatconvertTofloat(Object obj) Converts the given object to afloat.static FloatconvertToFloat(Object obj) Converts the given object to aByte.static intconvertToint(Object obj) Converts the given object to anint.static IntegerconvertToInt(Object obj) Converts the given object to anInteger.static longconvertTolong(Object obj) Converts the given object to along.static LongconvertToLong(Object obj) Converts the given object to aLong.static shortconvertToshort(Object obj) Converts the given object to ashort.static ShortconvertToShort(Object obj) Converts the given object to ashort.
-
Constructor Details
-
DefaultConverter
public DefaultConverter()Default constructor
-
-
Method Details
-
convertToint
Converts the given object to anint.- 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
Converts the given object to anInteger.- Parameters:
obj- the object to convert- Returns:
- the converted Integer, or
nullif the object isnull - Throws:
ConvertException- if the object cannot be converted to an Integer
-
convertToshort
Converts the given object to ashort.- 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
Converts the given object to ashort.- 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
Converts the given object to along.- 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
Converts the given object to aLong.- Parameters:
obj- the object to convert- Returns:
- the converted Long, or
nullif the object isnull - Throws:
ConvertException- if the object cannot be converted to a Long
-
convertTobyte
Converts the given object to abyte.- 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
Converts the given object to aByte.- Parameters:
obj- the object to convert- Returns:
- the converted Byte, or
nullif the object isnull - Throws:
ConvertException- if the object cannot be converted to a Byte
-
convertTofloat
Converts the given object to afloat.- 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
Converts the given object to aByte.- Parameters:
obj- the object to convert- Returns:
- the converted Byte, or
nullif the object isnull - Throws:
ConvertException- if the object cannot be converted to a Byte
-
convertTodouble
Converts the given object to adouble.- 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
Converts the given object to aDouble.- Parameters:
obj- the object to convert- Returns:
- the converted Double, or
nullif the object isnull - Throws:
ConvertException- if the object cannot be converted to a Double
-
convertTochar
Converts the given object to achar.- Parameters:
obj- the object to convert- Returns:
- the converted char value, or a space character if the object is
nullor the string is empty - Throws:
ConvertException- if the object cannot be converted to a char
-
convertToChar
Converts the given object to aCharacter.- Parameters:
obj- the object to convert- Returns:
- the converted Character, or
nullif the object isnull - Throws:
ConvertException- if the object cannot be converted to a Character
-
convertTobool
Converts the given object to aboolean.- Parameters:
obj- the object to convert- Returns:
- the converted boolean value, false if the object is
nullor represents the numeric value 0 - Throws:
ConvertException- if the object cannot be converted to a boolean
-
convertToBool
Converts the given object to aBoolean.- Parameters:
obj- the object to convert- Returns:
- the converted Boolean, or
nullif the object isnull - Throws:
ConvertException- if the object cannot be converted to a Boolean
-