Class JsonValueUtils


  • public final class JsonValueUtils
    extends Object
    Contains some JsonValue Utility methods.
    • Method Detail

      • expand

        public static JsonValue expand​(Map<String,​Object> object)
        Expands a Json Object Map, where the keys of the map are the JsonPointer s and the values are the value the JsonPointer resolves to. For Example, the following key-value pairs
              /object/array/0 , "test"
              /object/array/1 , "test1"
              /string         , "stringVal"
              /boolean        , false
              /number         , 1
              /array/0        , "value1"
              /array/1        , "value2"
         
        will produce the following json object
             {
                 "object" : {
                     "array" : ["test", "test1"]
                 },
                 "string" : "stringVal",
                 "boolean" : false,
                 "number" : 1,
                 "array" : ["value1", "value2"]
             }
         
        Parameters:
        object - the Json Object Map containing the JsonPointer s and values
        Returns:
        the JsonValue expanded from the object map
      • flatten

        public static Map<String,​Object> flatten​(JsonValue jsonValue)
        Flattens a JsonValue to a Map, where the keys of the Map are JsonPointer s and the values are the value the JsonPointer s resolve to. For Example, the following JsonValue
             {
                 "object" : {
                     "array" : ["test", "test1"]
                 },
                 "string" : "stringVal",
                 "boolean" : false,
                 "number" : 1,
                 "array" : ["value1", "value2"]
             }
         
        will produce the following Map key-value pairs
              /object/array/0 , "test"
              /object/array/1 , "test1"
              /string         , "stringVal"
              /boolean        , false
              /number         , 1
              /array/0        , "value1"
              /array/1        , "value2"
         
        Parameters:
        jsonValue - the JsonValue object to flatten
        Returns:
        a Map representing the flattened JsonValue object
      • extractValueAsString

        public static String extractValueAsString​(JsonValue json,
                                                  String fieldName)
        Extracts String representation of field identified by fieldName from json object. JsonValue transformers are applied up to fieldName but not to its components.
        Parameters:
        json - the JsonValue object from which to extract a value.
        fieldName - the field identifier in a form consumable by JsonPointer.
        Returns:
        A non-null String representation of the field's value. If the specified field is not present or has a null value, null will be returned.
      • extractValueAsString

        public static String extractValueAsString​(JsonValue json,
                                                  JsonPointer pointer)
        Extracts String representation of field identified by pointer from json object. JsonValue transformers are applied up to fieldName but not to its components.
        Parameters:
        json - the JsonValue object from which to extract a value.
        pointer - the field identifier as a JsonPointer.
        Returns:
        A non-null String representation of the field's value. If the specified field is not present or has a null value, null will be returned.