Package org.forgerock.json
Class JsonPatch
- java.lang.Object
- 
- org.forgerock.json.JsonPatch
 
- 
 public final class JsonPatch extends Object Processes partial modifications to JSON values.
- 
- 
Field SummaryFields Modifier and Type Field Description static JsonPointerFROM_PTRPath to the "from" attribute of a patch entry.static StringMEDIA_TYPEInternet media type for the JSON Patch format.static JsonPointerOP_PTRPath to the "op" attribute of a patch entry.static JsonPointerPATH_PTRPath to the "path" attribute of a patch entry.static JsonPointerVALUE_PTRPath to the "value" attribute of a patch entry.
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static JsonValuediff(JsonValue original, JsonValue target)Compares two JSON values, and produces a JSON Patch value, which contains the operations necessary to modify theoriginalvalue to arrive at thetargetvalue.static booleanisEqual(JsonValue value, JsonValue other)Compares two JSON values, and returns whether the two objects are identical.static JsonValuemerge(JsonValue first, JsonValue second)Creates a new JSON value which combines the contents two JSON values.static voidpatch(JsonValue original, JsonValue patch)Applies a set of modifications in a JSON patch value to an original value, resulting in the intended target value.static voidpatch(JsonValue original, JsonValue patch, JsonPatchValueTransformer transform)Applies a set of modifications in a JSON patch value to an original value, resulting in the intended target value.
 
- 
- 
- 
Field Detail- 
MEDIA_TYPEpublic static final String MEDIA_TYPE Internet media type for the JSON Patch format.- See Also:
- Constant Field Values
 
 - 
OP_PTRpublic static final JsonPointer OP_PTR Path to the "op" attribute of a patch entry. Required.
 - 
PATH_PTRpublic static final JsonPointer PATH_PTR Path to the "path" attribute of a patch entry. Required.
 - 
FROM_PTRpublic static final JsonPointer FROM_PTR Path to the "from" attribute of a patch entry. Required only for "move" and "copy" operations. Ignored for all others.
 - 
VALUE_PTRpublic static final JsonPointer VALUE_PTR Path to the "value" attribute of a patch entry. Required for "add", "replace" and "test" operations; Ignored for all others. This is public to allow for alternate implementations ofJsonPatchValueTransformer.
 
- 
 - 
Method Detail- 
diffpublic static JsonValue diff(JsonValue original, JsonValue target) Compares two JSON values, and produces a JSON Patch value, which contains the operations necessary to modify theoriginalvalue to arrive at thetargetvalue.- Parameters:
- original- the original value.
- target- the intended target value.
- Returns:
- the resulting JSON Patch value.
- Throws:
- NullPointerException- if either of- originalor- targetare- null.
 
 - 
mergepublic static JsonValue merge(JsonValue first, JsonValue second) Creates a new JSON value which combines the contents two JSON values.If there are any matching pointers in the two JSON values, then the value in secondoverrides the value in thefirst.- Parameters:
- first- the first JSON value.
- second- the second JSON value.
- Returns:
- a new JSON value which combines the contents of firstandsecond.
- Throws:
- NullPointerException- if either of- firstor- secondare- null.
 
 - 
isEqualpublic static boolean isEqual(JsonValue value, JsonValue other) Compares two JSON values, and returns whether the two objects are identical. Fails fast in that afalseis returned as soon as a difference is detected.- Parameters:
- value- a value.
- other- another value.
- Returns:
- whether the two inputs are equal.
- Throws:
- NullPointerException- if either of- valueor- otherare- null.
- IllegalArgumentException- if the- JsonValuecontains non-JSON primitive values.
 
 - 
patchpublic static void patch(JsonValue original, JsonValue patch) Applies a set of modifications in a JSON patch value to an original value, 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:
- original- the original value on which to apply the modifications.
- patch- the JSON Patch value, specifying the modifications to apply to the original value.
- Throws:
- JsonValueException- if application of the patch failed.
 
 - 
patchpublic static void patch(JsonValue original, JsonValue patch, JsonPatchValueTransformer transform) Applies a set of modifications in a JSON patch value to an original value, 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:
- original- the original value on which to apply the modifications.
- patch- the JSON Patch value, specifying the modifications to apply to the original value.
- transform- a custom transform used to determine the target value.
- Throws:
- JsonValueException- if application of the patch failed.
 
 
- 
 
-