Package org.pipservices3.commons.convert
Class MapConverter
java.lang.Object
org.pipservices3.commons.convert.MapConverter
Converts arbitrary values into map objects.
Converts using extended conversion rules:
- Objects: property names as keys, property values as values
- Arrays: element indexes as keys, elements as values
### Example ###
Map<String, Object> value1 = MapConverted.toNullableMap("ABC"); // Result: null
Map<String, Object> value2 = MapConverted.toNullableMap({ key: 123 }); // Result: { key: 123 }
Map<String, Object> value3 = MapConverted.toNullableMap(new int[]{1, 2, 3}); // Result: { "0": 1, "1": 2, "2": 3 }
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionConverts value into map object or returns empty map when conversion is not possibletoMapWithDefault
(Object value, Map<String, Object> defaultValue) Converts value into map object or returns default when conversion is not possibletoNullableMap
(Object value) Converts value into map object or returns null when conversion is not possible.
-
Constructor Details
-
MapConverter
public MapConverter()
-
-
Method Details
-
toNullableMap
Converts value into map object or returns null when conversion is not possible.- Parameters:
value
- the value to convert.- Returns:
- map object or null when conversion is not supported.
-
toMap
Converts value into map object or returns empty map when conversion is not possible- Parameters:
value
- the value to convert.- Returns:
- map object or empty map when conversion is not supported.
- See Also:
-
toMapWithDefault
Converts value into map object or returns default when conversion is not possible- Parameters:
value
- the value to convert.defaultValue
- the default value.- Returns:
- map object or empty map when conversion is not supported.
- See Also:
-