Package org.apache.juneau.internal
Class ConverterUtils
java.lang.Object
org.apache.juneau.internal.ConverterUtils
Utility class for efficiently converting objects between types.
If the value isn't an instance of the specified type, then converts the value if possible.
The following conversions are valid:
Convert to type | Valid input value types | Notes |
---|---|---|
A class that is the normal type of a registered ObjectSwap .
|
A value whose class matches the transformed type of that registered ObjectSwap .
|
|
A class that is the transformed type of a registered ObjectSwap .
|
A value whose class matches the normal type of that registered ObjectSwap .
|
|
Number (e.g. Integer , Short , Float ,...)
Number. (e.g. Integer. ,
Short. , Float. ,...)
|
Number , String , |
For primitive TYPES , |
Map (e.g. Map , HashMap , TreeMap , JsonMap )
|
Map
|
If Map is not constructible, an JsonMap is created.
|
|
|
If |
|
|
|
|
|
|
|
|
|
Bean |
|
|
|
Anything | Arrays are converted to JSON arrays |
Anything with one of the following methods:
|
|
|
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Boolean
Converts an object to a Boolean.static Integer
Converts an object to an Integer.static Number
Converts an object to a Number.static <T> T
Converts the specified object to the specified type.static <T> T
Converts the specified object to the specified type.
-
Constructor Details
-
ConverterUtils
public ConverterUtils()
-
-
Method Details
-
toType
Converts the specified object to the specified type.- Type Parameters:
T
- The class type to convert the value to.- Parameters:
value
- The value to convert.type
- The class type to convert the value to.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException
- If the specified value cannot be converted to the specified type.
-
toType
Converts the specified object to the specified type.- Type Parameters:
T
- The class type to convert the value to.- Parameters:
value
- The value to convert.type
- The class type to convert the value to.args
- The type arguments.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException
- If the specified value cannot be converted to the specified type.
-
toBoolean
Converts an object to a Boolean.- Parameters:
o
- The object to convert.- Returns:
- The converted object.
-
toInteger
Converts an object to an Integer.- Parameters:
o
- The object to convert.- Returns:
- The converted object.
-
toNumber
Converts an object to a Number.- Parameters:
o
- The object to convert.- Returns:
- The converted object.
-