Class MapConverter

java.lang.Object
org.pipservices3.commons.convert.MapConverter

public class MapConverter extends Object
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 Details

    • MapConverter

      public MapConverter()
  • Method Details

    • toNullableMap

      public static Map<String,Object> toNullableMap(Object value)
      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

      public static Map<String,Object> toMap(Object value)
      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

      public static Map<String,Object> toMapWithDefault(Object value, Map<String,Object> defaultValue)
      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: