Class RecursiveMapConverter

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

public class RecursiveMapConverter extends Object
Converts arbitrary values into map objects using extended conversion rules. This class is similar to MapConverter, but is recursively converts all values stored in objects and arrays.

### Example ###

 
 Map<String, Object> value1 = RecursiveMapConverted.toNullableMap("ABC"); // Result: null
 Map<String, Object> value2 = RecursiveMapConverted.toNullableMap({ key: 123 }); // Result: { key: 123 }
 List<Object> result = new ArrayList<Object>();
 result.add(1);
 result.add(new int[]{2, 3});
 Map<String, Object> value3 = RecursiveMapConverted.toNullableMap(result); // Result: { "0": 1, { "0": 2, "1": 3 } }
 
 
  • Constructor Details

    • RecursiveMapConverter

      public RecursiveMapConverter()
  • 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: