Package org.forgerock.audit.util
Class JsonValueUtils
- java.lang.Object
-
- org.forgerock.audit.util.JsonValueUtils
-
public final class JsonValueUtils extends Object
Contains some JsonValue Utility methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JsonValue
expand(Map<String,Object> object)
Expands a Json Object Map, where the keys of the map are theJsonPointer
s and the values are the value theJsonPointer
resolves to.static String
extractValueAsString(JsonValue json, String fieldName)
Extracts String representation of field identified byfieldName
fromjson
object.static String
extractValueAsString(JsonValue json, JsonPointer pointer)
Extracts String representation of field identified bypointer
fromjson
object.static Map<String,Object>
flatten(JsonValue jsonValue)
Flattens aJsonValue
to a Map, where the keys of the Map areJsonPointer
s and the values are the value theJsonPointer
s resolve to.
-
-
-
Method Detail
-
expand
public static JsonValue expand(Map<String,Object> object)
Expands a Json Object Map, where the keys of the map are theJsonPointer
s and the values are the value theJsonPointer
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 theJsonPointer
s and values- Returns:
- the
JsonValue
expanded from the object map
-
flatten
public static Map<String,Object> flatten(JsonValue jsonValue)
Flattens aJsonValue
to a Map, where the keys of the Map areJsonPointer
s and the values are the value theJsonPointer
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"
-
extractValueAsString
public static String extractValueAsString(JsonValue json, String fieldName)
Extracts String representation of field identified byfieldName
fromjson
object.JsonValue
transformers are applied up tofieldName
but not to its components.- Parameters:
json
- theJsonValue
object from which to extract a value.fieldName
- the field identifier in a form consumable byJsonPointer
.- 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 bypointer
fromjson
object.JsonValue
transformers are applied up tofieldName
but not to its components.- Parameters:
json
- theJsonValue
object from which to extract a value.pointer
- the field identifier as aJsonPointer
.- 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.
-
-