JsonPatch.java revision bf6542c5aa722eb97a0df17e6db46cc884f203bf
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions Copyrighted [year] [name of copyright owner]".
*
* Copyright 2011-2015 ForgeRock AS. All rights reserved.
*/
// Java SE
// JSON Fluent
/**
* Processes partial modifications to JSON values. Implements
* <a href="http://tools.ietf.org/html/rfc6902#section-4.1">RFC 6902 - JSON Patch</a>.
*/
public final class JsonPatch {
/**
* Internet media type for the JSON Patch format.
*/
/**
* Path to the "op" attribute of a patch entry. Required.
*/
/**
* Path to the "path" attribute of a patch entry. Required.
*/
/**
* Path to the "from" attribute of a patch entry. Required only for "move" and "copy"
* operations. Ignored for all others.
*/
/**
* 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 of {@link JsonPatchValueTransformer}.
*/
/**
* Default transform for patch values; Conforms to RFC6902.
*/
private static final JsonPatchValueTransformer DEFAULT_TRANSFORM =
new JsonPatchValueTransformer() {
}
}
};
/**
* Compares two JSON values, and produces a JSON Patch value, which contains the
* operations necessary to modify the {@code original} value to arrive at the
* {@code target} value.
*
* @param original the original value.
* @param target the intended target value.
* @return the resulting JSON Patch value.
* @throws NullPointerException if either of {@code original} or {@code target} are {@code null}.
*/
}
} else { // property is missing in target
}
}
}
}
boolean replace = false;
replace = true;
} else {
replace = true;
break;
}
}
}
if (replace) { // replace list entirely
}
} else if (!original.isNull() && !original.getObject().equals(target.getObject())) { // simple value comparison
}
}
/**
* Returns {@code true} if the type contained by {@code v1} is different than the type
* contained by {@code v2}.
* <p>
* Note: If an unexpected (non-JSON) type is encountered, this method returns
* {@code true}, triggering a change in the resulting patch.
*/
}
}
return result;
}
/**
* 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.
*
* @param original the original value on which to apply the modifications.
* @param patch the JSON Patch value, specifying the modifications to apply to the original value.
* @throws JsonValueException if application of the patch failed.
*/
}
/**
* 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.
*
* @param original the original value on which to apply the modifications.
* @param patch the JSON Patch value, specifying the modifications to apply to the original value.
* @param transform a custom transform used to determine the target value.
* @throws JsonValueException if application of the patch failed.
*/
public static void patch(JsonValue original, JsonValue patch, JsonPatchValueTransformer transform) {
}
}
}
}
private enum PatchOperation {
ADD {
// http://tools.ietf.org/html/rfc6902#section-4.1
// patch specifies a new root object
}
} else {
try {
try {
// if the path points to an array index then we should insert the value
} catch (Exception e) {
// leaf is not an array index, replace value
}
// modifyPath does not indicate an index, use the whole object
} else {
// this will replace the value even if present
}
} catch (JsonException je) {
}
}
}
},
REMOVE {
//http://tools.ietf.org/html/rfc6902#section-4.2
// patch specifies root object
} else {
}
try {
} catch (JsonException je) {
}
}
}
},
REPLACE {
//http://tools.ietf.org/html/rfc6902#section-4.3
// replacing a child
}
} else {
// replacing the root value itself
}
}
},
MOVE {
// http://tools.ietf.org/html/rfc6902#section-4.4
if (sourceParent == null) {
}
if (destParent == null) {
// replacing root object with moved object
} else {
}
}
},
COPY {
// http://tools.ietf.org/html/rfc6902#section-4.5
if (destParent == null) {
// replacing root object with copied object
} else {
}
}
},
TEST {
// http://tools.ietf.org/html/rfc6902#section-4.6
}
}
};
}
}
}
/**
* Returns the parent value of the value identified by the JSON pointer.
*
* @param pointer the pointer to the value whose parent value is to be returned.
* @param target the JSON value against which to resolve the JSON pointer.
* @return the parent value of the value identified by the JSON pointer.
* @throws JsonException if the parent value could not be found.
*/
throw new JsonException("parent value not found");
}
}
return result;
}
// prevent construction
private JsonPatch() {
}
}