public final class ConverterUtils extends Object
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 PojoSwap .
|
A value whose class matches the transformed type of that registered PojoSwap .
|
|
A class that is the transformed type of a registered PojoSwap .
|
A value whose class matches the normal type of that registered PojoSwap .
|
|
Number (e.g. Integer , Short , Float ,...)
Number. (e.g. Integer. ,
Short. , Float. ,...)
|
Number , String , |
For primitive TYPES , |
Map (e.g. Map , HashMap , TreeMap , OMap )
|
Map
|
If Map is not constructible, an OMap is created.
|
|
|
If |
|
|
|
|
|
|
|
|
|
Bean |
|
|
|
Anything | Arrays are converted to JSON arrays |
Anything with one of the following methods:
|
|
|
Constructor and Description |
---|
ConverterUtils() |
Modifier and Type | Method and Description |
---|---|
static Boolean |
toBoolean(Object o)
Converts an object to a Boolean.
|
static Integer |
toInteger(Object o)
Converts an object to an Integer.
|
static Number |
toNumber(Object o)
Converts an object to a Number.
|
static <T> T |
toType(Object value,
Class<T> type)
Converts the specified object to the specified type.
|
static <T> T |
toType(Object value,
Class<T> type,
Type... args)
Converts the specified object to the specified type.
|
public ConverterUtils()
public static <T> T toType(Object value, Class<T> type)
T
- The class type to convert the value to.value
- The value to convert.type
- The class type to convert the value to.InvalidDataConversionException
- If the specified value cannot be converted to the specified type.public static <T> T toType(Object value, Class<T> type, Type... args)
T
- The class type to convert the value to.value
- The value to convert.type
- The class type to convert the value to.args
- The type arguments.InvalidDataConversionException
- If the specified value cannot be converted to the specified type.public static Boolean toBoolean(Object o)
o
- The object to convert.public static Integer toInteger(Object o)
o
- The object to convert.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.