JOHNZON-95 first bits of MergeBatch handling
Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/eb932c35 Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/eb932c35 Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/eb932c35 Branch: refs/heads/master Commit: eb932c35e91c0a6762716570f1b452796a837d06 Parents: 0e4bd48 Author: Mark Struberg <[email protected]> Authored: Wed Nov 23 22:51:37 2016 +0100 Committer: Mark Struberg <[email protected]> Committed: Mon Dec 5 21:35:12 2016 +0100 ---------------------------------------------------------------------- .../johnzon/core/JsonMergePatchBuilder.java | 74 ++++++++++++++++++++ .../johnzon/core/JsonMergeBatchBuilderTest.java | 36 ++++++++++ 2 files changed, 110 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/johnzon/blob/eb932c35/johnzon-core/src/main/java/org/apache/johnzon/core/JsonMergePatchBuilder.java ---------------------------------------------------------------------- diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonMergePatchBuilder.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonMergePatchBuilder.java new file mode 100644 index 0000000..831e82e --- /dev/null +++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonMergePatchBuilder.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.johnzon.core; + +import javax.json.JsonValue; + +/** + * Creates and applies a Json Merge Patch as defined in + * https://tools.ietf.org/html/rfc7396 + */ +public class JsonMergePatchBuilder { + + /** + * Create a merged patch by comparing the source to the target. + * Applying this JsonPatch to the source will give you the target. + * A mergePatch is a JsonValue as defined in http://tools.ietf.org/html/rfc7396 + * + * If you have a JSON like + * <pre> + * { + * "a": "b", + * "c": { + * "d": "e", + * "f": "g" + * } + * } + * </pre> + * + * Then you can change the value of "a" and removing "f" by sending: + * <pre> + * { + * "a":"z", + * "c": { + * "f": null + * } + * } + * </pre> + * + * @see #mergePatch(JsonValue, JsonValue) + * + * @since 1.1 + */ + public JsonValue createMergePatch(JsonValue source , JsonValue target) { + return null; + } + + /** + * Merge the given patch to the existing source + * A mergePatch is a JsonValue as defined in http://tools.ietf.org/html/rfc7396 + * + * @return the result of applying the patch to the source + * + * @see #createMergePatch(JsonValue, JsonValue) + * @since 1.1 + */ + public JsonValue mergePatch(JsonValue source, JsonValue patch) { + return null; + } + +} http://git-wip-us.apache.org/repos/asf/johnzon/blob/eb932c35/johnzon-core/src/test/java/org/apache/johnzon/core/JsonMergeBatchBuilderTest.java ---------------------------------------------------------------------- diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonMergeBatchBuilderTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonMergeBatchBuilderTest.java new file mode 100644 index 0000000..141ed9d --- /dev/null +++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonMergeBatchBuilderTest.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.johnzon.core; + +import javax.json.spi.JsonProvider; + +public class JsonMergeBatchBuilderTest { + + private static final String[][] TEST_CASES = new String[][]{ + { + "{\"a\":\"b\"}", + "{\"a\":\"c\"}", + "{\"a\":\"c\"}" + } + }; + + public void testSimpleMergePatch() { + JsonProvider provider = JsonProvider.provider(); + + + } +}
