Class JsonValue
- java.lang.Object
-
- org.forgerock.json.JsonValue
-
-
Constructor Summary
Constructors Constructor Description JsonValue(Object object)Constructs a JSON value object with a given object.JsonValue(Object object, JsonPointer pointer)Constructs a JSON value object with a given object and pointer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonValueadd(int index, Object object)Adds the specified value to the list.JsonValueadd(Object object)Adds the specified value to the end of the list.JsonValueadd(String key, Object object)Adds the specified value.JsonValueadd(JsonPointer pointer, Object object)Adds the value identified by the specified pointer, relative to this value as root.JsonValueaddIfNotNull(String key, Object object)Adds the specified object value only if it is not nullJsonValueaddPermissive(JsonPointer pointer, Object object)Adds the value identified by the specified pointer, relative to this value as root.static List<Object>array(Object... objects)Returns a mutable JSON array containing the provided objects.<V,E extends Exception>
Vas(Function<JsonValue,V,E> transformFunction)Returns the JSON value as an object whose type (and value) is specified by a transformation function.<V,E extends Exception>
Promise<V,E>asAsync(AsyncFunction<JsonValue,V,E> transformFunction)Returns the JSON value as a promised object whose type (and value) is specified by a transformation function.BooleanasBoolean()Returns the JSON value as aBooleanobject.Collection<Object>asCollection()Returns the JSON value as aCollectionobject.<E> Collection<E>asCollection(Class<E> type)Returns the JSON value as aCollectioncontaining objects of the specified type.DoubleasDouble()Returns the JSON value as aDoubleobject.IntegerasInteger()Returns the JSON value as anIntegerobject.List<Object>asList()Returns the JSON value as aListobject.<E> List<E>asList(Class<E> type)Returns the JSON value as aListcontaining objects of the specified type.LongasLong()Returns the JSON value as aLongobject.Map<String,Object>asMap()Returns the JSON value as aMapobject.<V> Map<String,V>asMap(Class<V> type)Returns the JSON value as aMapcontaining objects of the specified type.<E> Map<String,List<E>>asMapOfList(Class<E> elementType)Returns the JSON value as aMapcontaining a collection of objects of the specified type.NumberasNumber()Returns the JSON value as aNumberobject.StringasString()Returns the JSON value as aStringobject.voidclear()Removes all child values from this JSON value, if it has any.JsonValueclone()Returns a shallow copy of this JSON value.booleancontains(Object object)Returnstruethis JSON value contains an item with the specified value.JsonValuecopy()Returns a deep copy of this JSON value.JsonValuedefaultTo(Object object)Defaults the JSON value to the specified value if it is currentlynull.JsonValuediff(JsonValue target)Performs a deep comparison of this JSON vlaue with another JSON value, and produces a JSON Patch value, which contains the operations necessary to modify the current value to arrive at thetargetvalue.JsonValueexpect(Class<?> type)Called to enforce that the JSON value is of a particular type.static Map.Entry<String,Object>field(String key, Object value)Returns a JSON field for inclusion in a JSON object usingobject.static Map.Entry<String,Object>fieldIfNotNull(String key, Object value)Returns a JSON field for inclusion in a JSON object usingobjectonly if its value is notnull.JsonValueget(int index)Returns the specified child value.JsonValueget(String key)Returns the specified item value.JsonValueget(JsonPointer pointer)Returns the specified child value with a pointer, relative to this value as root.ObjectgetObject()Returns the raw Java object representing this JSON value.JsonPointergetPointer()Returns the pointer of the JSON value in its JSON structure.booleanisBoolean()Returnstrueif the JSON value is aBoolean.booleanisCollection()Returnstrueif the JSON value is aCollection.booleanisDefined(String key)Returnstrueif this JSON value contains the specified item.booleanisEqualTo(JsonValue other)Performs a deep comparison of this JSON value with another JSON value, and returns whether the two objects are identical.booleanisList()Returnstrueif the JSON value is aList.booleanisMap()Returnstrueif the JSON value is aMap.booleanisNotNull()Returnstrueif the value is notnull.booleanisNull()Returnstrueif the value isnull.booleanisNumber()Returnstrueif the JSON value is aNumber.booleanisString()Returnstrueif the JSON value is aString.Iterator<JsonValue>iterator()Returns an iterator over the child values that this JSON value contains.static JsonValuejson(Object object)Returns a JSON value whose content is the provided object.Set<String>keys()Returns the set of keys for this JSON value's child values.JsonValuemerge(JsonValue other)Creates a new JSON value which combines the contents this JSON value with another.static Map<String,Object>object(int size)Produces an empty JSON object pre-allocated forsizefields.static Map<String,Object>object(Map.Entry<String,Object>... fields)Returns a JSON object comprised of the provided JSONfields.voidpatch(JsonValue patch)Applies a set of modifications in a JSON patch value to the current object, resulting in the intended target value.JsonValueput(int index, Object object)Sets the value of the specified child list element.JsonValueput(String key, Object object)Sets the value of the specified member.JsonValueput(JsonPointer pointer, Object object)Sets the value identified by the specified pointer, relative to this value as root.JsonValueputIfNotNull(String key, Object object)Sets the value of the specified member, only if it is not null.JsonValueputPermissive(JsonPointer pointer, Object object)Sets the value identified by the specified pointer, relative to this value as root.voidremove(int index)Removes the specified child value, shifting any subsequent elements to the left.voidremove(String key)Removes the specified child value.voidremove(JsonPointer pointer)Removes the specified child value with a pointer, relative to this value as root.JsonValuerequired()Throws aJsonValueExceptionif the JSON value isnull.voidsetObject(Object object)Sets the Java object representing this JSON value.intsize()Returns the number of values that this JSON value contains.Stream<JsonValue>stream()Construct a Stream from this JsonValue object.static inttoIndex(String key)Returns the key as an list index value.StringtoString()Returns a string representation of the JSON value.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
JsonValue
public JsonValue(Object object)
Constructs a JSON value object with a given object. This constructor will automatically unwrapJsonValueobjects.- Parameters:
object- the Java object representing the JSON value.
-
JsonValue
public JsonValue(Object object, JsonPointer pointer)
Constructs a JSON value object with a given object and pointer. This constructor will automatically unwrapJsonValueobjects.- Parameters:
object- the Java object representing the JSON value.pointer- the pointer to the value in a JSON structure.
-
-
Method Detail
-
array
public static List<Object> array(Object... objects)
Returns a mutable JSON array containing the provided objects. This method is provided as a convenience method for constructing JSON arrays. Example usage:JsonValue value = json(array(1, 2, 3));
- Parameters:
objects- The array elements.- Returns:
- A JSON array.
-
fieldIfNotNull
public static Map.Entry<String,Object> fieldIfNotNull(String key, Object value)
Returns a JSON field for inclusion in a JSON object usingobjectonly if its value is notnull. Example usage:JsonValue value = json(object(fieldIfNotNull("uid", getUid()));Note: This feature depends on the
object(java.util.Map.Entry...)method that checks if the entry is notnullbefore including it into the map.- Parameters:
key- The JSON field name.value- The JSON field value (may benull).- Returns:
- The JSON field for inclusion in a JSON object or
null. - See Also:
object(java.util.Map.Entry...)
-
field
public static Map.Entry<String,Object> field(String key, Object value)
Returns a JSON field for inclusion in a JSON object usingobject. This method is provided as a convenience method for constructing JSON objects. Example usage:JsonValue value = json(object(field("uid", "bjensen"), field("age", 30)));- Parameters:
key- The JSON field name.value- The JSON field value.- Returns:
- The JSON field for inclusion in a JSON object.
-
json
public static JsonValue json(Object object)
Returns a JSON value whose content is the provided object. This method is provided as a convenience method for constructing JSON objects, instead of usingJsonValue(Object). Example usage:JsonValue value = json(object(field("uid", "bjensen"), field("roles", array("sales", "marketing"))));- Parameters:
object- the Java object representing the JSON value.- Returns:
- The JSON value.
-
object
@SafeVarargs public static Map<String,Object> object(Map.Entry<String,Object>... fields)
Returns a JSON object comprised of the provided JSONfields. This method is provided as a convenience method for constructing JSON objects. Example usage:JsonValue value = json(object(field("uid", "bjensen"), field("age", 30)));- Parameters:
fields- The list offieldsto include in the JSON object.nullelements are allowed, but are not included in the returned map (this makes it easier to include optional elements).- Returns:
- The JSON object.
-
object
public static Map<String,Object> object(int size)
Produces an empty JSON object pre-allocated forsizefields. This method is provided as a convenience method for constructing JSON objects. Example usage:JsonValue value = json(object(20)); for (Map.Entry<String, Object> entry : someMap.entrySet()) { value.put(entry.getKey(), entry.getValue()); }- Parameters:
size- The size of the JSON object to allocate.- Returns:
- The [empty] JSON object.
-
toIndex
public static int toIndex(String key)
Returns the key as an list index value. If the string does not represent a valid list index value, then-1is returned.- Parameters:
key- the key to be converted into an list index value.- Returns:
- the converted index value, or
-1if invalid.
-
add
public JsonValue add(int index, Object object)
Adds the specified value to the list. Adding a value to a list shifts any existing elements at or above the specified index to the right by one.- Parameters:
index- theListindex of the value to add.object- the java object to add.- Returns:
- this JSON value.
- Throws:
JsonValueException- if this JSON value is not aListor index is out of range.
-
add
public JsonValue add(JsonPointer pointer, Object object)
Adds the value identified by the specified pointer, relative to this value as root. If doing so would require the creation of a new object or list, aJsonValueExceptionwill be thrown.NOTE: values may be added to a list using the reserved JSON pointer token "-". For example, the pointer "/a/b/-" will add a new element to the list referenced by "/a/b".
- Parameters:
pointer- identifies the child value to add.object- the Java object value to add.- Returns:
- this JSON value.
- Throws:
JsonValueException- if the specified pointer is invalid.
-
add
public JsonValue add(Object object)
Adds the specified value to the end of the list. This method is equivalent to the following code:add(size(), object);
- Parameters:
object- the java object to add.- Returns:
- this JSON value.
- Throws:
JsonValueException- if this JSON value is not aList.
-
add
public JsonValue add(String key, Object object)
Adds the specified value.If adding to a list value, the specified key must be parseable as an unsigned base-10 integer and be less than or equal to the list size. Adding a value to a list shifts any existing elements at or above the specified index to the right by one.
- Parameters:
key- theMapkey orListindex to add.object- the Java object to add.- Returns:
- this JSON value.
- Throws:
JsonValueException- if not aMaporList, theMapkey already exists, or theListindex is out of range.
-
addIfNotNull
public JsonValue addIfNotNull(String key, Object object)
Adds the specified object value only if it is not nullFor further usage information, see documentation for
add(String, Object).- Parameters:
key- theMapkey orListindex to add.object- the Java object to add.- Returns:
- this JSON value.
- Throws:
JsonValueException- if not aMaporList, theMapkey already exists, or theListindex is out of range.
-
addPermissive
public JsonValue addPermissive(JsonPointer pointer, Object object)
Adds the value identified by the specified pointer, relative to this value as root. Missing parent objects or lists will be created on demand.NOTE: values may be added to a list using the reserved JSON pointer token "-". For example, the pointer "/a/b/-" will add a new element to the list referenced by "/a/b".
- Parameters:
pointer- identifies the child value to add.object- the Java object value to add.- Returns:
- this JSON value.
- Throws:
JsonValueException- if the specified pointer is invalid.
-
asBoolean
public Boolean asBoolean()
- Returns:
- the boolean value.
- Throws:
JsonValueException- if the JSON value is not a boolean type.
-
asDouble
public Double asDouble()
Returns the JSON value as aDoubleobject. This may involve rounding. If the JSON value isnull, this method returnsnull.- Returns:
- the double-precision floating point value.
- Throws:
JsonValueException- if the JSON value is not a number.
-
asInteger
public Integer asInteger()
Returns the JSON value as anIntegerobject. This may involve rounding or truncation. If the JSON value isnull, this method returnsnull.- Returns:
- the integer value.
- Throws:
JsonValueException- if the JSON value is not a number.
-
asCollection
public Collection<Object> asCollection()
- Returns:
- the collection value, or
nullif no value. - Throws:
JsonValueException- if the JSON value is not aCollection.
-
asList
public List<Object> asList()
Returns the JSON value as aListobject. If the JSON value isnull, this method returnsnull. The returnedListis not a copy : any interaction with it will affect theJsonValue.- Returns:
- the list value, or
nullif no value. - Throws:
JsonValueException- if the JSON value is not aList.
-
asCollection
public <E> Collection<E> asCollection(Class<E> type)
Returns the JSON value as aCollectioncontaining objects of the specified type. If the value isnull, this method returnsnull. If any of the elements of the collection are notnulland not of the specified type,JsonValueExceptionis thrown. The returnedCollectionis not a copy : any interaction with it will affect theJsonValue.- Type Parameters:
E- the type of elements in this collection- Parameters:
type- the type of object that all elements are expected to be.- Returns:
- the collection value, or
nullif no value. - Throws:
JsonValueException- if the JSON value is not aCollectionor contains an unexpected type.NullPointerException- iftypeisnull.
-
asList
public <E> List<E> asList(Class<E> type)
Returns the JSON value as aListcontaining objects of the specified type. If the value isnull, this method returnsnull. If any of the elements of the list are notnulland not of the specified type,JsonValueExceptionis thrown. The returnedListis not a copy : any interaction with it will affect theJsonValue.- Type Parameters:
E- the type of elements in this list- Parameters:
type- the type of object that all elements are expected to be.- Returns:
- the list value, or
nullif no value. - Throws:
JsonValueException- if the JSON value is not aListor contains an unexpected type.NullPointerException- iftypeisnull.
-
as
public <V,E extends Exception> V as(Function<JsonValue,V,E> transformFunction) throws E extends Exception
Returns the JSON value as an object whose type (and value) is specified by a transformation function. It is up to the transformation function to transform/enforce source types of the elements in the Json source element and to decide what to do depending on the kind ofJsonValue: if it is null, aString, aList, orMap. If the type-transformation cannot occur, the exception specified by the transformation function is thrown.- Type Parameters:
V- the type of elementE- the type of exception thrown by the transformation function- Parameters:
transformFunction- aFunctionto transform the JsonValue element to the desired type- Returns:
- the value, or
nullif no value. - Throws:
E- if the JsonValue element cannot be transformedNullPointerException- iftransformFunctionisnull.E extends Exception
-
asAsync
public <V,E extends Exception> Promise<V,E> asAsync(AsyncFunction<JsonValue,V,E> transformFunction)
Returns the JSON value as a promised object whose type (and value) is specified by a transformation function. It is up to the transformation function to transform/enforce source types of the elements in the Json source element and to decide what to do depending on the kind ofJsonValue: if it is null, aString, aList, orMap. If the type-transformation cannot occur, the exception specified by the transformation function is thrown.- Type Parameters:
V- the type of elementE- the type of exception thrown by the transformation function- Parameters:
transformFunction- aFunctionto transform the JsonValue element to the desired type- Returns:
- the promise of the value, the final value may be null, but the promise itself can't. In case of exception the result promise is failed and contains the exception.
-
asLong
public Long asLong()
Returns the JSON value as aLongobject. This may involve rounding or truncation. If the JSON value isnull, this method returnsnull.- Returns:
- the long integer value.
- Throws:
JsonValueException- if the JSON value is not a number.
-
asMap
public Map<String,Object> asMap()
Returns the JSON value as aMapobject. If the JSON value isnull, this method returnsnull.- Returns:
- the map value, or
nullif no value. - Throws:
JsonValueException- if the JSON value is not aMap.
-
asMap
public <V> Map<String,V> asMap(Class<V> type)
Returns the JSON value as aMapcontaining objects of the specified type. If the value isnull, this method returnsnull. If any of the values of the map are notnulland not of the specified type,JsonValueExceptionis thrown.- Type Parameters:
V- the type of values in this map- Parameters:
type- the type of object that all values are expected to be.- Returns:
- the map value, or
nullif no value. - Throws:
JsonValueException- if the JSON value is not aMapor contains an unexpected type.NullPointerException- iftypeisnull.
-
asMapOfList
public <E> Map<String,List<E>> asMapOfList(Class<E> elementType)
Returns the JSON value as aMapcontaining a collection of objects of the specified type. If the value isnull, this method returnsnull. If any of the values of the map are notnulland not of the specified type,JsonValueExceptionis thrown.- Type Parameters:
E- the type of elements in the collection- Parameters:
elementType- the type of object that all collection elements are expected to be.- Returns:
- the map value, or
nullif no value. - Throws:
JsonValueException- if the JSON value is not aMapor contains an unexpected type.NullPointerException- iftypeisnull.
-
asNumber
public Number asNumber()
Returns the JSON value as aNumberobject. If the JSON value isnull, this method returnsnull.- Returns:
- the numeric value.
- Throws:
JsonValueException- if the JSON value is not a number.
-
asString
public String asString()
Returns the JSON value as aStringobject. If the JSON value isnull, this method returnsnull.- Returns:
- the string value.
- Throws:
JsonValueException- if the JSON value is not a string.
-
clear
public void clear()
Removes all child values from this JSON value, if it has any.
-
clone
public JsonValue clone()
Returns a shallow copy of this JSON value. If this JSON value contains aMapor aListobject, the returned JSON value will contain a shallow copy of the original contained object.The new value's members can be modified without affecting the original value. Modifying the member's members will almost certainly affect the original value. To avoid this, use the
copy()method to return a deep copy of the JSON value.This method does not traverse the value's members, nor will it apply any transformations.
-
contains
public boolean contains(Object object)
Returnstruethis JSON value contains an item with the specified value.- Parameters:
object- the object to seek within this JSON value.- Returns:
trueif this value contains the specified member value.
-
copy
public JsonValue copy()
Returns a deep copy of this JSON value.Note: This method is recursive, and currently has no ability to detect or correct for structures containing cyclic references. Processing such a structure will result in a
StackOverflowErrorbeing thrown.- Returns:
- a deep copy of this JSON value.
-
defaultTo
public JsonValue defaultTo(Object object)
Defaults the JSON value to the specified value if it is currentlynull.- Parameters:
object- the object to default to.- Returns:
- this JSON value or a new JSON value containing the default value.
-
expect
public JsonValue expect(Class<?> type)
Called to enforce that the JSON value is of a particular type. A value ofnullis allowed.- Parameters:
type- the class that the underlying value must have.- Returns:
- this JSON value.
- Throws:
JsonValueException- if the value is not the specified type.
-
get
public JsonValue get(int index)
Returns the specified child value. If this JSON value is not aListor if no such child exists, then a JSON value containing anullis returned.- Parameters:
index- index of child element value to return.- Returns:
- the child value, or a JSON value containing
null. - Throws:
JsonValueException- if index is negative.
-
get
public JsonValue get(JsonPointer pointer)
Returns the specified child value with a pointer, relative to this value as root. If the specified child value does not exist, thennullis returned.- Parameters:
pointer- the JSON pointer identifying the child value to return.- Returns:
- the child value, or
nullif no such value exists.
-
get
public JsonValue get(String key)
Returns the specified item value. If no such member value exists, then a JSON value containingnullis returned.- Parameters:
key- theMapkey orListindex identifying the item to return.- Returns:
- a JSON value containing the value or
null.
-
getObject
public Object getObject()
Returns the raw Java object representing this JSON value.- Returns:
- the raw Java object representing this JSON value.
-
getPointer
public JsonPointer getPointer()
Returns the pointer of the JSON value in its JSON structure.- Returns:
- the pointer of the JSON value in its JSON structure.
-
isBoolean
public boolean isBoolean()
Returnstrueif the JSON value is aBoolean.- Returns:
trueif the JSON value is aBoolean.
-
isDefined
public boolean isDefined(String key)
Returnstrueif this JSON value contains the specified item.- Parameters:
key- theMapkey orListindex of the item to seek.- Returns:
trueif this JSON value contains the specified member.- Throws:
NullPointerException- ifkeyisnull.
-
isCollection
public boolean isCollection()
Returnstrueif the JSON value is aCollection.- Returns:
trueif the JSON value is aCollection.
-
isList
public boolean isList()
Returnstrueif the JSON value is aList.- Returns:
trueif the JSON value is aList.
-
isMap
public boolean isMap()
Returnstrueif the JSON value is aMap.- Returns:
trueif the JSON value is aMap.
-
isNull
public boolean isNull()
Returnstrueif the value isnull.- Returns:
trueif the value isnull.
-
isNotNull
public boolean isNotNull()
Returnstrueif the value is notnull.- Returns:
trueif the value is notnull.
-
isNumber
public boolean isNumber()
Returnstrueif the JSON value is aNumber.- Returns:
trueif the JSON value is aNumber.
-
isString
public boolean isString()
Returnstrueif the JSON value is aString.- Returns:
trueif the JSON value is aString.
-
iterator
public Iterator<JsonValue> iterator()
Returns an iterator over the child values that this JSON value contains. If this value is aMap, then the order of the resulting child values is undefined. Calling theIterator.remove()method of the returned iterator will throw aUnsupportedOperationException.
-
keys
public Set<String> keys()
Returns the set of keys for this JSON value's child values. If this value is aMap, then the order of the resulting keys is the same as the underlying Map implementation. If there are no child values, this method returns an empty set.- Returns:
- the set of keys for this JSON value's child values.
-
put
public JsonValue put(int index, Object object)
Sets the value of the specified child list element.- Parameters:
index- theListindex identifying the child value to set.object- the Java value to assign to the list element.- Returns:
- this JSON value.
- Throws:
JsonValueException- if this JSON value is not aListor index is out of range.
-
putIfNotNull
public JsonValue putIfNotNull(String key, Object object)
Sets the value of the specified member, only if it is not null.For further usage information, see documentation for
put(String, Object).- Parameters:
key- theMapkey orListindex identifying the child value to set.object- the object value to assign to the member.- Returns:
- this JSON value.
- Throws:
JsonValueException- if this JSON value is not aMaporList.NullPointerException- ifkeyisnull.
-
put
public JsonValue put(JsonPointer pointer, Object object)
Sets the value identified by the specified pointer, relative to this value as root. If doing so would require the creation of a new object or list, aJsonValueExceptionwill be thrown.NOTE: values may be added to a list using the reserved JSON pointer token "-". For example, the pointer "/a/b/-" will add a new element to the list referenced by "/a/b".
- Parameters:
pointer- identifies the child value to set.object- the Java object value to set.- Returns:
- this JSON value.
- Throws:
JsonValueException- if the specified pointer is invalid.
-
put
public JsonValue put(String key, Object object)
Sets the value of the specified member.If setting a list element, the specified key must be parseable as an unsigned base-10 integer and be less than or equal to the size of the list.
- Parameters:
key- theMapkey orListindex identifying the child value to set.object- the object value to assign to the member.- Returns:
- this JSON value.
- Throws:
JsonValueException- if this JSON value is not aMaporList.NullPointerException- ifkeyisnull.
-
putPermissive
public JsonValue putPermissive(JsonPointer pointer, Object object)
Sets the value identified by the specified pointer, relative to this value as root. Missing parent objects or lists will be created on demand.NOTE: values may be added to a list using the reserved JSON pointer token "-". For example, the pointer "/a/b/-" will add a new element to the list referenced by "/a/b".
- Parameters:
pointer- identifies the child value to set.object- the Java object value to set.- Returns:
- this JSON value.
- Throws:
JsonValueException- if the specified pointer is invalid.
-
remove
public void remove(int index)
Removes the specified child value, shifting any subsequent elements to the left. If the JSON value is not aList, calling this method has no effect.- Parameters:
index- theListindex identifying the child value to remove.
-
remove
public void remove(JsonPointer pointer)
Removes the specified child value with a pointer, relative to this value as root. If the specified child value is not defined, calling this method has no effect.- Parameters:
pointer- the JSON pointer identifying the child value to remove.
-
remove
public void remove(String key)
Removes the specified child value. If the specified child value is not defined, calling this method has no effect.- Parameters:
key- theMapkey orListindex identifying the child value to remove.
-
required
public JsonValue required()
Throws aJsonValueExceptionif the JSON value isnull.- Returns:
- this JSON value.
- Throws:
JsonValueException- if the JSON value isnull.
-
setObject
public void setObject(Object object)
Sets the Java object representing this JSON value.This method will automatically unwrap
JsonValueobjects.- Parameters:
object- the object to set.
-
size
public int size()
Returns the number of values that this JSON value contains.- Returns:
- the number of values that this JSON value contains.
-
toString
public String toString()
Returns a string representation of the JSON value. The result resembles—but is not guaranteed to conform to—JSON syntax. This method does not apply transformations to the value's children.
-
isEqualTo
public boolean isEqualTo(JsonValue other)
Performs a deep comparison of this JSON value with another JSON value, and returns whether the two objects are identical. Fails fast in that afalseis returned as soon as a difference is detected.Note: Only values recognisable as JSON primitives (
Map,List,Number,Boolean,Stringandnull) are supported.- Parameters:
other- another value.- Returns:
- whether the two objects are equal.
- Throws:
NullPointerException- ifotherisnull.IllegalArgumentException- if this or theothervalue contains non-JSON primitive values.
-
diff
public JsonValue diff(JsonValue target)
Performs a deep comparison of this JSON vlaue with another JSON value, and produces a JSON Patch value, which contains the operations necessary to modify the current value to arrive at thetargetvalue.- Parameters:
target- the intended target value.- Returns:
- the resulting JSON Patch value.
- Throws:
NullPointerException- if either oforiginalortargetarenull.
-
patch
public void patch(JsonValue patch)
Applies a set of modifications in a JSON patch value to the current object, resulting in the intended target value. In the event of a failure, this method does not revert any modifications applied up to the point of failure.- Parameters:
patch- the JSON Patch value, specifying the modifications to apply to the original value.- Throws:
JsonValueException- if application of the patch failed.
-
merge
public JsonValue merge(JsonValue other)
Creates a new JSON value which combines the contents this JSON value with another.If there are any matching pointers in the two JSON values, then the value in
otheroverrides the value inthis.- Parameters:
other- Another JSON value which should be merged with this one.- Returns:
- a new JSON value which combines the contents of this JSON value and
other.
-
-