public final class ObjectUtils 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 , ObjectMap )
|
Map
|
If Map is not constructible, a ObjectMap is created.
|
Collection (e.g. List , LinkedList , HashSet , ObjectList )
|
Collection<Object>
Object[]
|
If Collection is not constructible, a ObjectList is created.
|
X[] (array of any type X)
|
List<X>
|
|
X[][] (multi-dimensional arrays)
|
List<List<X>>
List<X[]>
List[]<X>
|
|
Enum
|
String
|
|
Bean |
Map
|
|
String
|
Anything | Arrays are converted to JSON arrays |
Anything with one of the following methods:
|
String
|
|
Constructor and Description |
---|
ObjectUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
equals(Object o1,
Object o2)
Returns
|
static <T> T |
firstNonNull(T[] t)
Returns the first non-null value in the specified array
|
static boolean |
isEmpty(Object o)
Returns
|
static Boolean |
toBoolean(Object o)
Converts an object to a Boolean.
|
static Integer |
toInteger(Object o)
Converts an object to an Integer.
|
static <T> T |
toMemberType(Object outer,
Object value,
Class<T> type)
Converts the specified object to the specified type.
|
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 ObjectUtils()
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 <T> T toMemberType(Object outer, Object value, Class<T> type)
T
- The class type to convert the value to.outer
- If class is a member class, this is the instance of the containing class.
Should be 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 boolean equals(Object o1, Object o2)
Gracefully handles
o1
- Object #1o2
- Object #2public static boolean isEmpty(Object o)
Return
Object.toString()
.
o
- The object to test.public static <T> T firstNonNull(T[] t)
t
- public static Boolean toBoolean(Object o)
o
- The object to convert.public static Integer toInteger(Object o)
o
- The object to convert.Copyright © 2018 Apache. All rights reserved.