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 JsonValueexpand(Map<String,Object> object)Expands a Json Object Map, where the keys of the map are theJsonPointers and the values are the value theJsonPointerresolves to.static StringextractValueAsString(JsonValue json, String fieldName)Extracts String representation of field identified byfieldNamefromjsonobject.static StringextractValueAsString(JsonValue json, JsonPointer pointer)Extracts String representation of field identified bypointerfromjsonobject.static Map<String,Object>flatten(JsonValue jsonValue)Flattens aJsonValueto a Map, where the keys of the Map areJsonPointers and the values are the value theJsonPointers 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 theJsonPointers and the values are the value theJsonPointerresolves 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 theJsonPointers and values- Returns:
- the
JsonValueexpanded from the object map
-
flatten
public static Map<String,Object> flatten(JsonValue jsonValue)
Flattens aJsonValueto a Map, where the keys of the Map areJsonPointers and the values are the value theJsonPointers 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 byfieldNamefromjsonobject.JsonValuetransformers are applied up tofieldNamebut not to its components.- Parameters:
json- theJsonValueobject 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 bypointerfromjsonobject.JsonValuetransformers are applied up tofieldNamebut not to its components.- Parameters:
json- theJsonValueobject 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.
-
-