Class ConverterUtils
java.lang.Object
org.apache.juneau.marshall.internal.ConverterUtils
Utility class for common type conversions and building typed collections and maps.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BooleanConverts an object to a Boolean.static IntegerConverts an object to an Integer.static <T> Lists<T>toListBuilder(Object value, Class<T> type) Converts the specified object to aListswith elements of the specified type.static <K,V> Maps<K, V> toMapBuilder(Object value, Class<K> keyType, Class<V> valueType) Converts the specified object to aMapswith keys and values of the specified types.static NumberConverts an object to a Number.static <T> Sets<T>toSetBuilder(Object value, Class<T> type) Converts the specified object to aSetswith elements of the specified type.static <T> TConverts the specified object to the specified type.
-
Method Details
-
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.
-
toType
Converts the specified object to the specified type.Uses the full
MarshallingContextConverterto support bean-aware conversions such asMapto bean, bean to bean, andObjectSwaptransforms.- 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.
-
toListBuilder
Converts the specified object to aListswith elements of the specified type.The input value can be any of the following:
- An array of objects convertible to the element type
- A
Collectionof objects convertible to the element type - A single object convertible to the element type (creates a list with one element)
- A JSON array string that can be parsed into objects of the element type
- Type Parameters:
T- The element type.- Parameters:
value- The value to convert. Can benull (no elements are added; an empty builder is returned).type- The element type class.- Returns:
- A new
Listscontaining the converted elements.
-
toMapBuilder
Converts the specified object to aMapswith keys and values of the specified types.The input value can be any of the following:
- A
Mapwith entries convertible to the key/value types - A JSON object string that can be parsed into a map with the specified key/value types
- An object with bean properties that can be converted to map entries
- Type Parameters:
K- The key type.V- The value type.- Parameters:
value- The value to convert. Can benull (no entries are added; an empty builder is returned).keyType- The key type class.valueType- The value type class.- Returns:
- A new
Mapscontaining the converted entries.
- A
-
toSetBuilder
Converts the specified object to aSetswith elements of the specified type.The input value can be any of the following:
- An array of objects convertible to the element type
- A
Collectionof objects convertible to the element type - A single object convertible to the element type (creates a set with one element)
- A JSON array string that can be parsed into objects of the element type
Duplicate elements (after conversion) will be automatically removed as per
Setsemantics.- Type Parameters:
T- The element type.- Parameters:
value- The value to convert. Can benull (no elements are added; an empty builder is returned).type- The element type class.- Returns:
- A new
Setscontaining the converted elements.
-