You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by st...@apache.org on 2016/11/22 21:06:36 UTC

[1/6] johnzon git commit: Update geronimo-json-spec from 1.0 to 1.1, add JsonPointer encode and decode methods

Repository: johnzon
Updated Branches:
  refs/heads/JSONP-1.1 c378b9b05 -> 24b01af8e


Update geronimo-json-spec from 1.0 to 1.1, add JsonPointer encode and decode methods


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/28748ffb
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/28748ffb
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/28748ffb

Branch: refs/heads/JSONP-1.1
Commit: 28748ffb18ff541c6d313c482024de255d60afd9
Parents: c378b9b
Author: Armin Hasler <ha...@gmail.com>
Authored: Fri Jun 24 14:49:29 2016 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Tue Nov 22 21:23:15 2016 +0100

----------------------------------------------------------------------
 .../apache/johnzon/core/JsonPointerUtil.java    | 37 ++++++++++++++++++++
 .../johnzon/core/JsonPointerUtilTest.java       |  7 ++++
 2 files changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/28748ffb/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
new file mode 100644
index 0000000..276fb42
--- /dev/null
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+public class JsonPointerUtil {
+
+    /**
+     *
+     * @param s
+     * @return
+     */
+    public static String encode(String s) {
+        return null;
+    }
+
+    public static String decode(String s) {
+        return null;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/johnzon/blob/28748ffb/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
new file mode 100644
index 0000000..226d742
--- /dev/null
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
@@ -0,0 +1,7 @@
+package org.apache.johnzon.core;
+
+/**
+ * @author Armin Hasler (02eex458)
+ */
+public class JsonPointerUtilTest {
+}


[2/6] johnzon git commit: Update geronimo-json-spec from 1.0 to 1.1, add JsonPointer encode and decode methods

Posted by st...@apache.org.
Update geronimo-json-spec from 1.0 to 1.1, add JsonPointer encode and decode methods


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/d8a56d05
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/d8a56d05
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/d8a56d05

Branch: refs/heads/JSONP-1.1
Commit: d8a56d05cd1d22c85ecad781cdbef4f01f77697c
Parents: 28748ff
Author: Mark Struberg <st...@apache.org>
Authored: Tue Nov 22 21:26:02 2016 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Tue Nov 22 21:26:02 2016 +0100

----------------------------------------------------------------------
 .../apache/johnzon/core/JsonPointerUtil.java    | 24 +++--
 .../johnzon/core/JsonPointerUtilTest.java       | 97 +++++++++++++++++++-
 johnzon-distribution/pom.xml                    |  3 +-
 3 files changed, 113 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/d8a56d05/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
index 276fb42..91bc9c2 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerUtil.java
@@ -20,18 +20,30 @@ package org.apache.johnzon.core;
 
 public class JsonPointerUtil {
 
+    private JsonPointerUtil() {
+
+    }
+
     /**
-     *
-     * @param s
-     * @return
+     * Transforms "~" to "~0" and then "/" to "~1"
      */
     public static String encode(String s) {
-        return null;
+        if (s == null || s.length() == 0) {
+            return s;
+        }
+
+        return s.replace("~", "~0").replace("/", "~1");
     }
 
+    /**
+     * Transforms "~1" to "/" and then "~0" to "~",
+     */
     public static String decode(String s) {
-        return null;
-    }
+        if (s == null || s.length() == 0) {
+            return s;
+        }
 
+        return s.replace("~1", "/").replace("~0", "~");
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/johnzon/blob/d8a56d05/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
index 226d742..73b0e01 100644
--- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerUtilTest.java
@@ -1,7 +1,98 @@
+/*
+ * 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;
 
-/**
- * @author Armin Hasler (02eex458)
- */
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
 public class JsonPointerUtilTest {
+
+    @Test
+    public void testEncodeNull() {
+        assertNull(JsonPointerUtil.encode(null));
+    }
+
+    @Test
+    public void testEncodeEmptyString() {
+        String encodedString = JsonPointerUtil.encode("");
+        assertEquals("", encodedString);
+    }
+
+    @Test
+    public void testEncodeNoTransformation() {
+        String encodedString = JsonPointerUtil.encode("TestString");
+        assertEquals("TestString", encodedString);
+    }
+
+    @Test
+    public void testEncodeFirstTransformation() {
+        String encodedString = JsonPointerUtil.encode("~");
+        assertEquals("~0", encodedString);
+    }
+
+    @Test
+    public void testEncodeSecondTransformation() {
+        String encodedString = JsonPointerUtil.encode("/");
+        assertEquals("~1", encodedString);
+    }
+
+    @Test
+    public void testEncodeWholeTransformation() {
+        String decodedString = JsonPointerUtil.encode("~/");
+        assertEquals("~0~1", decodedString);
+    }
+
+    @Test
+    public void testDecodeNull() {
+        assertNull(JsonPointerUtil.decode(null));
+    }
+
+    @Test
+    public void testDecodeEmptyString() {
+        String decodedString = JsonPointerUtil.decode("");
+        assertEquals("", decodedString);
+    }
+
+    @Test
+    public void testDecodeNoTransformation() {
+        String decodedString = JsonPointerUtil.decode("TestString");
+        assertEquals("TestString", decodedString);
+    }
+
+    @Test
+    public void testDecodeFirstTransformation() {
+        String decodedString = JsonPointerUtil.decode("~1");
+        assertEquals("/", decodedString);
+    }
+
+    @Test
+    public void testDecodeSecondTransformation() {
+        String decodedString = JsonPointerUtil.decode("~0");
+        assertEquals("~", decodedString);
+    }
+
+    @Test
+    public void testDecodeWholeTransformation() {
+        String decodedString = JsonPointerUtil.decode("~01");
+        assertEquals("~1", decodedString);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/johnzon/blob/d8a56d05/johnzon-distribution/pom.xml
----------------------------------------------------------------------
diff --git a/johnzon-distribution/pom.xml b/johnzon-distribution/pom.xml
index c0e6e26..f6f468e 100644
--- a/johnzon-distribution/pom.xml
+++ b/johnzon-distribution/pom.xml
@@ -21,7 +21,7 @@
   <parent>
     <artifactId>johnzon</artifactId>
     <groupId>org.apache.johnzon</groupId>
-    <version>0.9.6-SNAPSHOT</version>
+    <version>0.9.4-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
 
@@ -49,7 +49,6 @@
       <scope>compile</scope>
       <classifier>javadoc</classifier>
     </dependency>
-
     <dependency>
       <groupId>org.apache.johnzon</groupId>
       <artifactId>johnzon-core</artifactId>


[3/6] johnzon git commit: Implemented JsonPointer add, replace and remove methods

Posted by st...@apache.org.
Implemented JsonPointer add, replace and remove methods


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/cc830c64
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/cc830c64
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/cc830c64

Branch: refs/heads/JSONP-1.1
Commit: cc830c64a4e6a175a02d13ad2ccf5140401530df
Parents: 45faea0
Author: Armin Hasler <ha...@gmail.com>
Authored: Mon Nov 14 10:09:22 2016 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Tue Nov 22 21:28:49 2016 +0100

----------------------------------------------------------------------
 .../org/apache/johnzon/core/JsonPointer.java    | 310 ++++++++++----
 .../apache/johnzon/core/JsonPointerTest.java    | 419 ++++++++++++++++++-
 2 files changed, 647 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/cc830c64/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
index af228be..ca942ef 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
@@ -18,11 +18,17 @@
  */
 package org.apache.johnzon.core;
 
+import javax.json.Json;
 import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
 import javax.json.JsonException;
 import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
 import javax.json.JsonStructure;
 import javax.json.JsonValue;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>This class is an immutable representation of a JSON Pointer as specified in
@@ -49,7 +55,8 @@ import javax.json.JsonValue;
 public class JsonPointer {
 
     private final String jsonPointer;
-    private final String[] referenceTokens;
+    private final List<String> referenceTokens = new ArrayList<String>();
+    private final String lastReferenceToken;
 
     /**
      * Constructs and initializes a JsonPointer.
@@ -63,11 +70,16 @@ public class JsonPointer {
             throw new NullPointerException("jsonPointer must not be null");
         }
         if (!jsonPointer.equals("") && !jsonPointer.startsWith("/")) {
-            throw new JsonException("A non-empty JSON pointer must begin with a '/'");
+            throw new JsonException("A non-empty JsonPointer string must begin with a '/'");
         }
 
         this.jsonPointer = jsonPointer;
-        referenceTokens = jsonPointer.split("/", -1);
+        String[] encodedReferenceTokens = jsonPointer.split("/", -1);
+
+        for (String encodedReferenceToken : encodedReferenceTokens) {
+            referenceTokens.add(JsonPointerUtil.decode(encodedReferenceToken));
+        }
+        lastReferenceToken = referenceTokens.get(referenceTokens.size() - 1);
     }
 
     /**
@@ -113,43 +125,14 @@ public class JsonPointer {
         if (target == null) {
             throw new NullPointerException("target must not be null");
         }
-
-        if (jsonPointer.equals("")) {
+        if (isEmptyJsonPointer()) {
             return target;
         }
 
         JsonValue jsonValue = target;
-
-        for (int i = 1; i < referenceTokens.length; i++) {
-            String decodedReferenceToken = JsonPointerUtil.decode(referenceTokens[i]);
-
-            if (jsonValue instanceof JsonObject) {
-                JsonObject jsonObject = (JsonObject) jsonValue;
-                jsonValue = jsonObject.get(decodedReferenceToken);
-
-                if (jsonValue == null) {
-                    throw new JsonException("The JsonObject " + jsonObject + " contains no value for token " + decodedReferenceToken);
-                }
-            } else if (jsonValue instanceof JsonArray) {
-                JsonArray jsonArray = (JsonArray) jsonValue;
-
-                try {
-                    int index = Integer.parseInt(decodedReferenceToken);
-                    if (index >= jsonArray.size()) {
-                        throw new JsonException("The JsonArray " + jsonArray + " contains no element for index " + index);
-                    }
-                    if (decodedReferenceToken.startsWith("0") && decodedReferenceToken.length() > 1) {
-                        throw new JsonException("The token " + decodedReferenceToken + " with leading zeros is not allowed to reference an element of a JsonArray");
-                    }
-
-                    jsonValue = jsonArray.get(index);
-                } catch (NumberFormatException e) {
-                    throw new JsonException("The token " + decodedReferenceToken + " for the JsonArray " + jsonArray + " is not a number", e);
-                }
-            }
-
+        for (int i = 1; i < referenceTokens.size(); i++) {
+            jsonValue = getValue(jsonValue, referenceTokens.get(i), i, referenceTokens.size() - 1);
         }
-
         return jsonValue;
     }
 
@@ -179,35 +162,19 @@ public class JsonPointer {
      *                              or if the pointer contains references to non-existing objects or arrays.
      */
     public JsonStructure add(JsonStructure target, JsonValue value) {
-        return null;
-    }
-
-    /**
-     * Replaces the value at the referenced location in the specified
-     * {@code target} with the specified {@code value}.
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @param value  the value to be stored at the referenced location
-     * @return the transformed {@code target} after the value is replaced.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the referenced value does not exist,
-     *                              or if the reference is the target.
-     */
-    public JsonStructure replace(JsonStructure target, JsonValue value) {
-        return null;
-    }
+        validateAdd(target);
+        if (isEmptyJsonPointer()) {
+            if (value.getClass() != target.getClass()) {
+                throw new JsonException("The value must have the same type as the target");
+            }
+            return (JsonStructure) value;
+        }
 
-    /**
-     * Removes the value at the reference location in the specified {@code target}
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @return the transformed {@code target} after the value is removed.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the referenced value does not exist,
-     *                              or if the reference is the target.
-     */
-    public JsonStructure remove(JsonStructure target) {
-        return null;
+        if (target instanceof JsonObject) {
+            return add((JsonObject) target, value);
+        } else {
+            return add((JsonArray) target, value);
+        }
     }
 
     /**
@@ -224,7 +191,9 @@ public class JsonPointer {
      * @see #add(JsonStructure, JsonValue)
      */
     public JsonObject add(JsonObject target, JsonValue value) {
-        return (JsonObject) this.add((JsonStructure) target, value);
+        validateAdd(target);
+
+        return (JsonObject) add(target, 1, referenceTokens.size() - 1, value);
     }
 
     /**
@@ -241,7 +210,28 @@ public class JsonPointer {
      * @see #add(JsonStructure, JsonValue)
      */
     public JsonArray add(JsonArray target, JsonValue value) {
-        return (JsonArray) this.add((JsonStructure) target, value);
+        validateAdd(target);
+
+        return (JsonArray) add(target, 1, referenceTokens.size() - 1, value);
+    }
+
+    /**
+     * Replaces the value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be stored at the referenced location
+     * @return the transformed {@code target} after the value is replaced.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     */
+    public JsonStructure replace(JsonStructure target, JsonValue value) {
+        if (target instanceof JsonObject) {
+            return replace((JsonObject) target, value);
+        } else {
+            return replace((JsonArray) target, value);
+        }
     }
 
     /**
@@ -253,11 +243,10 @@ public class JsonPointer {
      * @throws NullPointerException if {@code target} is {@code null}
      * @throws JsonException        if the referenced value does not exist,
      *                              or if the reference is the target.
-     *                              {@code target} with the specified {@code value}.
      * @see #replace(JsonStructure, JsonValue)
      */
     public JsonObject replace(JsonObject target, JsonValue value) {
-        return (JsonObject) this.replace((JsonStructure) target, value);
+        return add(remove(target), value);
     }
 
     /**
@@ -269,11 +258,27 @@ public class JsonPointer {
      * @throws NullPointerException if {@code target} is {@code null}
      * @throws JsonException        if the referenced value does not exist,
      *                              or if the reference is the target.
-     *                              {@code target} with the specified {@code value}.
      * @see #replace(JsonStructure, JsonValue)
      */
     public JsonArray replace(JsonArray target, JsonValue value) {
-        return (JsonArray) this.replace((JsonStructure) target, value);
+        return add(remove(target), value);
+    }
+
+    /**
+     * Removes the value at the reference location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the transformed {@code target} after the value is removed.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     */
+    public JsonStructure remove(JsonStructure target) {
+        if (target instanceof JsonObject) {
+            return remove((JsonObject) target);
+        } else {
+            return remove((JsonArray) target);
+        }
     }
 
     /**
@@ -287,7 +292,9 @@ public class JsonPointer {
      * @see #remove(JsonStructure)
      */
     public JsonObject remove(JsonObject target) {
-        return (JsonObject) this.remove((JsonStructure) target);
+        validateRemove(target);
+
+        return (JsonObject) remove(target, 1, referenceTokens.size() - 1);
     }
 
     /**
@@ -301,8 +308,169 @@ public class JsonPointer {
      * @see #remove(JsonStructure)
      */
     public JsonArray remove(JsonArray target) {
-        return (JsonArray) this.remove((JsonStructure) target);
+        validateRemove(target);
+
+        return (JsonArray) remove(target, 1, referenceTokens.size() - 1);
+    }
+
+    private void validateAdd(JsonValue target) {
+        validateJsonPointer(target, referenceTokens.size() - 1);
     }
 
+    private void validateRemove(JsonValue target) {
+        validateJsonPointer(target, referenceTokens.size());
+        if (isEmptyJsonPointer()) {
+            throw new JsonException("The reference must not be the target");
+        }
+    }
+
+    private boolean isEmptyJsonPointer() {
+        return jsonPointer.equals("");
+    }
+
+    private JsonValue getValue(JsonValue jsonValue, String referenceToken, int currentPosition, int referencePosition) {
+        if (jsonValue instanceof JsonObject) {
+            JsonObject jsonObject = (JsonObject) jsonValue;
+            jsonValue = jsonObject.get(referenceToken);
+
+            if (jsonValue != null) {
+                return jsonValue;
+            }
+            throw new JsonException("'" + jsonObject + "' contains no value for name '" + referenceToken + "'");
+        } else if (jsonValue instanceof JsonArray) {
+            validateArrayIndex(referenceToken);
+
+            try {
+                JsonArray jsonArray = (JsonArray) jsonValue;
+                int arrayIndex = Integer.parseInt(referenceToken);
+                validateArraySize(jsonArray, arrayIndex, jsonArray.size());
+                return jsonArray.get(arrayIndex);
+            } catch (NumberFormatException e) {
+                throw new JsonException("'" + referenceToken + "' is no valid array index", e);
+            }
+        } else {
+            if (currentPosition != referencePosition) {
+                return jsonValue;
+            }
+            throw new JsonException("'" + jsonValue + "' contains no element for '" + referenceToken + "'");
+        }
+    }
+
+    private JsonValue add(JsonValue jsonValue, int currentPosition, int referencePosition, JsonValue newValue) {
+        if (jsonValue instanceof JsonObject) {
+            JsonObject jsonObject = (JsonObject) jsonValue;
+            JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
+
+            if (jsonObject.isEmpty()) {
+                objectBuilder.add(lastReferenceToken, newValue);
+            } else {
+                for (Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
+                    objectBuilder.add(entry.getKey(), add(entry.getValue(), currentPosition + 1, referencePosition, newValue));
+                    if (currentPosition == referencePosition) {
+                        objectBuilder.add(lastReferenceToken, newValue);
+                    }
+                }
+            }
+            return objectBuilder.build();
+        } else if (jsonValue instanceof JsonArray) {
+            JsonArray jsonArray = (JsonArray) jsonValue;
+            JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
+
+            int arrayIndex = -1;
+            if (currentPosition == referencePosition) {
+                arrayIndex = getArrayIndex(lastReferenceToken, jsonArray, true);
+            }
+
+            int jsonArraySize = jsonArray.size();
+            for (int i = 0; i <= jsonArraySize; i++) {
+                if (i == arrayIndex) {
+                    arrayBuilder.add(newValue);
+                }
+                if (i == jsonArraySize) {
+                    break;
+                }
+                arrayBuilder.add(add(jsonArray.get(i), currentPosition + 1, referencePosition, newValue));
+            }
+            return arrayBuilder.build();
+        }
+        return jsonValue;
+    }
+
+    private JsonValue remove(JsonValue jsonValue, int currentPosition, int referencePosition) {
+        if (jsonValue instanceof JsonObject) {
+            JsonObject jsonObject = (JsonObject) jsonValue;
+            JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
+
+            for (Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
+                if (currentPosition == referencePosition
+                        && lastReferenceToken.equals(entry.getKey())) {
+                    continue;
+                }
+                objectBuilder.add(entry.getKey(), remove(entry.getValue(), currentPosition + 1, referencePosition));
+            }
+            return objectBuilder.build();
+        } else if (jsonValue instanceof JsonArray) {
+            JsonArray jsonArray = (JsonArray) jsonValue;
+            JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
+
+            int arrayIndex = -1;
+            if (currentPosition == referencePosition) {
+                arrayIndex = getArrayIndex(lastReferenceToken, jsonArray, false);
+            }
+
+            int jsonArraySize = jsonArray.size();
+            for (int i = 0; i < jsonArraySize; i++) {
+                if (i == arrayIndex) {
+                    continue;
+                }
+                arrayBuilder.add(remove(jsonArray.get(i), currentPosition + 1, referencePosition));
+            }
+            return arrayBuilder.build();
+        }
+        return jsonValue;
+    }
+
+    private int getArrayIndex(String referenceToken, JsonArray jsonArray, boolean addOperation) {
+        if (addOperation && referenceToken.equals("-")) {
+            return jsonArray.size();
+        }
+
+        validateArrayIndex(referenceToken);
+
+        try {
+            int arrayIndex = Integer.parseInt(referenceToken);
+            int arraySize = addOperation ? jsonArray.size() + 1 : jsonArray.size();
+            validateArraySize(jsonArray, arrayIndex, arraySize);
+            return arrayIndex;
+        } catch (NumberFormatException e) {
+            throw new JsonException("'" + referenceToken + "' is no valid array index", e);
+        }
+    }
+
+    private void validateJsonPointer(JsonValue target, int size) throws NullPointerException, JsonException {
+        if (target == null) {
+            throw new NullPointerException("target must not be null");
+        }
+
+        JsonValue jsonValue = target;
+        for (int i = 1; i < size; i++) {
+            jsonValue = getValue(jsonValue, referenceTokens.get(i), i, referenceTokens.size() - 1);
+        }
+    }
+
+    private void validateArrayIndex(String referenceToken) throws JsonException {
+        if (referenceToken.startsWith("+") || referenceToken.startsWith("-")) {
+            throw new JsonException("An array index must not start with '" + referenceToken.charAt(0) + "'");
+        }
+        if (referenceToken.startsWith("0") && referenceToken.length() > 1) {
+            throw new JsonException("An array index must not start with a leading '0'");
+        }
+    }
+
+    private void validateArraySize(JsonArray jsonArray, int arrayIndex, int arraySize) throws JsonException {
+        if (arrayIndex >= arraySize) {
+            throw new JsonException("'" + jsonArray + "' contains no element for index " + arrayIndex);
+        }
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/johnzon/blob/cc830c64/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
index 7750ba6..9b6c722 100644
--- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
@@ -21,34 +21,38 @@ package org.apache.johnzon.core;
 import org.junit.Test;
 
 import javax.json.Json;
+import javax.json.JsonArray;
 import javax.json.JsonException;
+import javax.json.JsonObject;
 import javax.json.JsonReader;
 import javax.json.JsonStructure;
 import javax.json.JsonValue;
 import java.util.Collections;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class JsonPointerTest {
 
     @Test(expected = NullPointerException.class)
-    public void testConstructorWithNullShouldThrowNullPointerException() {
+    public void testConstructorWithJsonPointerNull() {
         new JsonPointer(null);
     }
 
     @Test(expected = JsonException.class)
-    public void testConstructorWithInvalidJsonPointerShouldThrowJsonException() {
+    public void testConstructorWithInvalidJsonPointer() {
         new JsonPointer("a");
     }
 
     @Test(expected = NullPointerException.class)
-    public void testGetValueWithNullShouldThrowNullPointerException() {
+    public void testGetValueWithTargetNull() {
         JsonPointer jsonPointer = new JsonPointer("");
         jsonPointer.getValue(null);
     }
 
     @Test
-    public void testGetValueWholeDocument() {
+    public void testGetValueWithWholeDocument() {
         JsonStructure jsonDocument = getJsonDocument();
 
         JsonPointer jsonPointer = new JsonPointer("");
@@ -138,7 +142,7 @@ public class JsonPointerTest {
     }
 
     @Test(expected = JsonException.class)
-    public void testGetValueElementNotExistentShouldThrowJsonException() {
+    public void testGetValueWithElementNotExistent() {
         JsonStructure jsonDocument = getJsonDocument();
 
         JsonPointer jsonPointer = new JsonPointer("/fool");
@@ -146,7 +150,7 @@ public class JsonPointerTest {
     }
 
     @Test
-    public void testGetValueWholeJsonArray() {
+    public void testGetValueWithWholeJsonArray() {
         JsonStructure jsonDocument = getJsonDocument();
 
         JsonPointer jsonPointer = new JsonPointer("/foo");
@@ -155,7 +159,7 @@ public class JsonPointerTest {
     }
 
     @Test
-    public void testGetValueJsonArrayElement() {
+    public void testGetValueWithJsonArray() {
         JsonStructure jsonDocument = getJsonDocument();
 
         JsonPointer jsonPointer = new JsonPointer("/foo/0");
@@ -164,7 +168,7 @@ public class JsonPointerTest {
     }
 
     @Test(expected = JsonException.class)
-    public void testGetValueJsonArrayElementNotExistentShouldThrowJsonException() {
+    public void testGetValueWithJsonArrayIndexOutOfRange() {
         JsonStructure jsonDocument = getJsonDocument();
 
         JsonPointer jsonPointer = new JsonPointer("/foo/2");
@@ -172,7 +176,7 @@ public class JsonPointerTest {
     }
 
     @Test(expected = JsonException.class)
-    public void testGetValueJsonArrayElementNoNumberShouldThrowJsonException() {
+    public void testGetValueWithJsonArrayIndexNoNumber() {
         JsonStructure jsonDocument = getJsonDocument();
 
         JsonPointer jsonPointer = new JsonPointer("/foo/a");
@@ -180,14 +184,407 @@ public class JsonPointerTest {
     }
 
     @Test(expected = JsonException.class)
-    public void testGetValueJsonArrayElementLeadingZeroShouldThrowJsonException() {
+    public void testGetValueWithJsonArrayLeadingZeroIndex() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/foo/001");
+        JsonPointer jsonPointer = new JsonPointer("/foo/01");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("\"bar\"", result.toString());
     }
 
+    @Test(expected = JsonException.class)
+    public void testGetValueWithJsonArrayInvalidIndex() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/foo/-1");
+        jsonPointer.getValue(jsonDocument);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testAddJsonStructureWithTargetNull() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        jsonPointer.add((JsonStructure) null, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testAddJsonStructureWithTypeValueNotTypeTarget() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        JsonObject target = Json.createObjectBuilder().build();
+        JsonArray value = Json.createArrayBuilder().build();
+
+        jsonPointer.add((JsonStructure) target, value);
+    }
+
+    @Test
+    public void testAddJsonStructureWithEmptyJsonPointer() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        JsonStructure target = Json.createObjectBuilder().build();
+        JsonObject value = Json.createObjectBuilder()
+                .add("foo", "bar").build(); // { "foo": "bar" }
+
+        JsonStructure result = jsonPointer.add(target, value);
+        assertEquals("{\"foo\":\"bar\"}", result.toString());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testAddJsonObjectWithTargetNull() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        jsonPointer.add((JsonObject) null, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testAddJsonArrayWithTargetNull() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        jsonPointer.add((JsonArray) null, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testAddArrayElementWithInvalidIndex() {
+        JsonPointer jsonPointer = new JsonPointer("/+");
+        JsonStructure target = Json.createArrayBuilder().build();
+
+        jsonPointer.add(target, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testAddArrayElementWithIndexOutOfRange() {
+        JsonPointer jsonPointer = new JsonPointer("/1");
+        JsonStructure target = Json.createArrayBuilder().build();
+
+        jsonPointer.add(target, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testAddArrayElementWithLeadingZeroIndex() {
+        JsonPointer jsonPointer = new JsonPointer("/01");
+        JsonStructure target = Json.createArrayBuilder()
+                .add("foo").build();
+
+        jsonPointer.add(target, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testAddArrayElementWithIndexNoNumber() {
+        JsonPointer jsonPointer = new JsonPointer("/a");
+        JsonStructure target = Json.createArrayBuilder()
+                .add("foo").build();
+
+        jsonPointer.add(target, new JsonStringImpl("qux"));
+    }
+
+    @Test
+    public void testAddObject() {
+        JsonPointer jsonPointer = new JsonPointer("/child");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", "bar").build(); // {"foo":"bar"}
+        JsonObject value = Json.createObjectBuilder()
+                .add("grandchild", Json.createObjectBuilder()).build(); // {"grandchild":{}}
+
+        JsonStructure result = jsonPointer.add(target, value);
+        assertEquals("{\"foo\":\"bar\",\"child\":{\"grandchild\":{}}}", result.toString()); // {"foo":"bar","child":{"grandchild":{}}}
+    }
+
+    @Test
+    public void testAddObjectMember() {
+        JsonPointer jsonPointer = new JsonPointer("/baz");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", "bar").build(); // {"foo":"bar"}
+
+        JsonStructure result = jsonPointer.add(target, new JsonStringImpl("qux"));
+        assertEquals("{\"foo\":\"bar\",\"baz\":\"qux\"}", result.toString()); // {"foo":"bar","baz":"qux"}
+    }
+
+    @Test
+    public void testAddFirstObjectMember() {
+        JsonPointer jsonPointer = new JsonPointer("/foo");
+        JsonStructure target = Json.createObjectBuilder().build(); // {}
+
+        JsonStructure result = jsonPointer.add(target, new JsonStringImpl("bar"));
+        assertEquals("{\"foo\":\"bar\"}", result.toString()); // {"foo":"bar"}
+    }
+
+    @Test(expected = JsonException.class)
+    public void testAddObjectMemberWithNonexistentTarget() {
+        JsonPointer jsonPointer = new JsonPointer("/baz/bat");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", "bar").build(); // {"foo":"bar"}
+
+        jsonPointer.add(target, new JsonStringImpl("qux"));
+    }
+
+    @Test
+    public void testAddReplaceObjectMember() {
+        JsonPointer jsonPointer = new JsonPointer("/baz");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("baz", "qux")
+                .add("foo", "bar").build(); // {"baz":"qux","foo":"bar"}
+
+        JsonStructure result = jsonPointer.add(target, new JsonStringImpl("boo"));
+        assertEquals("{\"baz\":\"boo\",\"foo\":\"bar\"}", result.toString()); // {"baz":"boo","foo":"bar"}
+    }
+
+    @Test
+    public void testAddArray() {
+        JsonPointer jsonPointer = new JsonPointer("/0/-");
+        JsonStructure target = Json.createArrayBuilder()
+                .add(Json.createArrayBuilder()
+                        .add("bar")).build(); // [["bar"]]
+        JsonArray value = Json.createArrayBuilder()
+                .add("abc")
+                .add("def").build();// ["abc","def"]
+
+        JsonStructure result = jsonPointer.add(target, value);
+        assertEquals("[[\"bar\",[\"abc\",\"def\"]]]", result.toString()); // [["bar",["abc","def"]]]
+    }
+
+    @Test
+    public void testAddArrayElement() {
+        JsonPointer jsonPointer = new JsonPointer("/foo/1");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", Json.createArrayBuilder()
+                        .add("bar")
+                        .add("baz")).build(); // {"foo":["bar","baz"]}
+
+        JsonStructure result = jsonPointer.add(target, new JsonStringImpl("qux"));
+        assertEquals("{\"foo\":[\"bar\",\"qux\",\"baz\"]}", result.toString()); // {"foo":["bar","qux","baz"]}
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testRemoveJsonObjectWithTargetNull() {
+        JsonPointer jsonPointer = new JsonPointer("/");
+        jsonPointer.remove((JsonObject) null);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testRemoveJsonObjectWithEmptyJsonPointer() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        JsonObject target = Json.createObjectBuilder().build();
+
+        jsonPointer.remove(target);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testRemoveJsonArrayWithTargetNull() {
+        JsonPointer jsonPointer = new JsonPointer("/");
+        jsonPointer.remove((JsonArray) null);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testRemoveJsonArrayWithEmptyJsonPointer() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        JsonArray target = Json.createArrayBuilder().build();
+
+        jsonPointer.remove(target);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testRemoveArrayElementWithIndexNoNumber() {
+        JsonPointer jsonPointer = new JsonPointer("/foo/a");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", Json.createArrayBuilder()
+                        .add("bar")
+                        .add("qux")
+                        .add("baz")).build(); // {"foo":["bar","qux","baz"]}
+
+        jsonPointer.remove(target);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testRemoveArrayElementWithIndexOutOfRange() {
+        JsonPointer jsonPointer = new JsonPointer("/foo/3");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", Json.createArrayBuilder()
+                        .add("bar")
+                        .add("qux")
+                        .add("baz")).build(); // {"foo":["bar","qux","baz"]}
+
+        jsonPointer.remove(target);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testRemoveArrayElementWithInvalidIndex() {
+        JsonPointer jsonPointer = new JsonPointer("/foo/+");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", Json.createArrayBuilder()
+                        .add("bar")
+                        .add("qux")
+                        .add("baz")).build(); // {"foo":["bar","qux","baz"]}
+
+        jsonPointer.remove(target);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testRemoveArrayElementWithLeadingZeroIndex() {
+        JsonPointer jsonPointer = new JsonPointer("/foo/01");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", Json.createArrayBuilder()
+                        .add("bar")
+                        .add("qux")
+                        .add("baz")).build(); // {"foo":["bar","qux","baz"]}
+
+        jsonPointer.remove(target);
+    }
+
+    @Test
+    public void testRemoveArrayElement() {
+        JsonPointer jsonPointer = new JsonPointer("/0/1");
+        JsonStructure target = Json.createArrayBuilder()
+                .add(Json.createArrayBuilder()
+                        .add("bar")
+                        .add("qux")
+                        .add("baz")).build(); // [["bar","qux","baz"]]
+
+        JsonStructure result = jsonPointer.remove(target);
+        assertEquals("[[\"bar\",\"baz\"]]", result.toString()); // [["bar","baz"]]
+    }
+
+    @Test
+    public void testRemoveObjectMember() {
+        JsonPointer jsonPointer = new JsonPointer("/baz");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("baz", "qux")
+                .add("foo", "bar").build(); // {"baz":"qux","foo":"bar"}
+
+        JsonStructure result = jsonPointer.remove(target);
+        assertEquals("{\"foo\":\"bar\"}", result.toString()); // {"foo":"bar"}
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testReplaceJsonObjectWithTargetNull() {
+        JsonPointer jsonPointer = new JsonPointer("/");
+        jsonPointer.replace((JsonObject) null, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testReplaceJsonObjectWithEmptyJsonPointer() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        JsonObject target = Json.createObjectBuilder().build();
+
+        jsonPointer.replace(target, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testReplaceJsonArrayWithTargetNull() {
+        JsonPointer jsonPointer = new JsonPointer("/");
+        jsonPointer.replace((JsonArray) null, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testReplaceJsonArrayWithEmptyJsonPointer() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        JsonArray target = Json.createArrayBuilder().build();
+
+        jsonPointer.replace(target, new JsonStringImpl("qux"));
+    }
+
+    @Test
+    public void testReplaceArrayElement() {
+        JsonPointer jsonPointer = new JsonPointer("/1/1");
+        JsonStructure target = Json.createArrayBuilder()
+                .add("bar")
+                .add(Json.createArrayBuilder()
+                        .add("abc")
+                        .add("def")).build(); // ["bar",["abc","def"]]
+
+        JsonStructure result = jsonPointer.replace(target, new JsonStringImpl("qux"));
+        assertEquals("[\"bar\",[\"abc\",\"qux\"]]", result.toString()); // ["bar",["abc","qux"]]
+    }
+
+    @Test(expected = JsonException.class)
+    public void testReplaceArrayElementWithIndexOutOfRange() {
+        JsonPointer jsonPointer = new JsonPointer("/1/2");
+        JsonStructure target = Json.createArrayBuilder()
+                .add("bar")
+                .add(Json.createArrayBuilder()
+                        .add("abc")
+                        .add("def")).build(); // ["bar",["abc","def"]]
+
+        jsonPointer.replace(target, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testReplaceArrayElementWithIndexNoNumber() {
+        JsonPointer jsonPointer = new JsonPointer("/1/a");
+        JsonStructure target = Json.createArrayBuilder()
+                .add("bar")
+                .add(Json.createArrayBuilder()
+                        .add("abc")
+                        .add("def")).build(); // ["bar",["abc","def"]]
+
+        jsonPointer.replace(target, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testReplaceArrayElementWithLeadingZeroIndex() {
+        JsonPointer jsonPointer = new JsonPointer("/1/01");
+        JsonStructure target = Json.createArrayBuilder()
+                .add("bar")
+                .add(Json.createArrayBuilder()
+                        .add("abc")
+                        .add("def")).build(); // ["bar",["abc","def"]]
+
+        jsonPointer.replace(target, new JsonStringImpl("qux"));
+    }
+
+    @Test(expected = JsonException.class)
+    public void testReplaceArrayElementWithInvalidIndex() {
+        JsonPointer jsonPointer = new JsonPointer("/1/+");
+        JsonStructure target = Json.createArrayBuilder()
+                .add("bar")
+                .add(Json.createArrayBuilder()
+                        .add("abc")
+                        .add("def")).build(); // ["bar",["abc","def"]]
+
+        jsonPointer.replace(target, new JsonStringImpl("qux"));
+    }
+
+    @Test
+    public void testReplaceObjectMember() {
+        JsonPointer jsonPointer = new JsonPointer("/baz");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", "bar")
+                .add("baz", "qux").build(); // {"foo":"bar","baz":"qux"}
+
+        JsonStructure result = jsonPointer.replace(target, new JsonStringImpl("boo"));
+        assertEquals("{\"foo\":\"bar\",\"baz\":\"boo\"}", result.toString()); // {"foo":"bar","baz":"boo"}
+    }
+
+    @Test(expected = JsonException.class)
+    public void testReplaceObjectMemberWithNonexistentTarget1() {
+        JsonPointer jsonPointer = new JsonPointer("/baz/a");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", "bar")
+                .add("baz", "qux").build(); // {"foo":"bar","baz":"qux"}
+
+        JsonStructure result = jsonPointer.replace(target, new JsonStringImpl("boo"));
+        assertEquals("{\"foo\":\"bar\",\"baz\":\"boo\"}", result.toString()); // {"foo":"bar","baz":"boo"}
+    }
+
+    @Test(expected = JsonException.class)
+    public void testReplaceObjectMemberWithNonexistentTarget2() {
+        JsonPointer jsonPointer = new JsonPointer("/fo");
+        JsonStructure target = Json.createObjectBuilder()
+                .add("foo", "bar")
+                .add("baz", "qux").build(); // {"foo":"bar","baz":"qux"}
+
+        JsonStructure result = jsonPointer.replace(target, new JsonStringImpl("boo"));
+        assertEquals("{\"foo\":\"bar\",\"baz\":\"boo\"}", result.toString()); // {"foo":"bar","baz":"boo"}
+    }
+
+    @Test
+    public void testEqualsTrue() {
+        JsonPointer jsonPointer1 = new JsonPointer("/foo/1");
+        JsonPointer jsonPointer2 = new JsonPointer("/foo/1");
+        assertTrue(jsonPointer1.equals(jsonPointer2));
+    }
+
+    @Test
+    public void testEqualsFalse() {
+        JsonPointer jsonPointer1 = new JsonPointer("/foo/1");
+        JsonPointer jsonPointer2 = new JsonPointer("/foo/2");
+        assertFalse(jsonPointer1.equals(jsonPointer2));
+    }
+
     private JsonStructure getJsonDocument() {
         JsonReader reader = Json.createReaderFactory(Collections.<String, Object>emptyMap()).createReader(
                 Thread.currentThread().getContextClassLoader().getResourceAsStream("json/jsonPointerTest.json"));


[4/6] johnzon git commit: Implemented JsonPointer

Posted by st...@apache.org.
Implemented JsonPointer


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/45faea0e
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/45faea0e
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/45faea0e

Branch: refs/heads/JSONP-1.1
Commit: 45faea0eb3e04f7adbe0724a448eb0cb62a4f258
Parents: d8a56d0
Author: Armin Hasler <ha...@gmail.com>
Authored: Wed Jul 6 17:06:26 2016 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Tue Nov 22 21:28:49 2016 +0100

----------------------------------------------------------------------
 .../org/apache/johnzon/core/JsonPointer.java    | 308 +++++++++++++++++++
 .../apache/johnzon/core/JsonPointerTest.java    | 197 ++++++++++++
 .../test/resources/json/jsonPointerTest.json    |  15 +
 3 files changed, 520 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/45faea0e/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
new file mode 100644
index 0000000..af228be
--- /dev/null
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
@@ -0,0 +1,308 @@
+/*
+ * 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.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import javax.json.JsonStructure;
+import javax.json.JsonValue;
+
+/**
+ * <p>This class is an immutable representation of a JSON Pointer as specified in
+ * <a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>.
+ * </p>
+ * <p> A JSON Pointer, when applied to a target {@link JsonValue},
+ * defines a reference location in the target.</p>
+ * <p> An empty JSON Pointer string defines a reference to the target itself.</p>
+ * <p> If the JSON Pointer string is non-empty, it must be a sequence
+ * of '/' prefixed tokens, and the target must either be a {@link JsonArray}
+ * or {@link JsonObject}. If the target is a {@code JsonArray}, the pointer
+ * defines a reference to an array element, and the last token specifies the index.
+ * If the target is a {@link JsonObject}, the pointer defines a reference to a
+ * name/value pair, and the last token specifies the name.
+ * </p>
+ * <p> The method {@link JsonPointer#getValue getValue()} returns the referenced value.
+ * The methods {@link JsonPointer#add add()}, {@link JsonPointer#replace replace()},
+ * and {@link JsonPointer#remove remove()} executes the operations specified in
+ * <a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>. </p>
+ *
+ * @since 1.1
+ */
+
+public class JsonPointer {
+
+    private final String jsonPointer;
+    private final String[] referenceTokens;
+
+    /**
+     * Constructs and initializes a JsonPointer.
+     *
+     * @param jsonPointer the JSON Pointer string
+     * @throws NullPointerException if {@code jsonPointer} is {@code null}
+     * @throws JsonException        if {@code jsonPointer} is not a valid JSON Pointer
+     */
+    public JsonPointer(String jsonPointer) {
+        if (jsonPointer == null) {
+            throw new NullPointerException("jsonPointer must not be null");
+        }
+        if (!jsonPointer.equals("") && !jsonPointer.startsWith("/")) {
+            throw new JsonException("A non-empty JSON pointer must begin with a '/'");
+        }
+
+        this.jsonPointer = jsonPointer;
+        referenceTokens = jsonPointer.split("/", -1);
+    }
+
+    /**
+     * Compares this {@code JsonPointer} with another object.
+     *
+     * @param obj the object to compare this {@code JsonPointer} against
+     * @return true if the given object is a {@code JsonPointer} with the same
+     * reference tokens as this one, false otherwise.
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+
+        JsonPointer that = (JsonPointer) obj;
+        return jsonPointer.equals(that.jsonPointer);
+    }
+
+    /**
+     * Returns the hash code value for this {@code JsonPointer} object.
+     * The hash code of this object is defined by the hash codes of it's reference tokens.
+     *
+     * @return the hash code value for this {@code JsonPointer} object
+     */
+    @Override
+    public int hashCode() {
+        return jsonPointer.hashCode();
+    }
+
+    /**
+     * Returns the value at the referenced location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the referenced value in the target.
+     * @throws NullPointerException if {@code target} is null
+     * @throws JsonException        if the referenced value does not exist
+     */
+    public JsonValue getValue(JsonStructure target) {
+        if (target == null) {
+            throw new NullPointerException("target must not be null");
+        }
+
+        if (jsonPointer.equals("")) {
+            return target;
+        }
+
+        JsonValue jsonValue = target;
+
+        for (int i = 1; i < referenceTokens.length; i++) {
+            String decodedReferenceToken = JsonPointerUtil.decode(referenceTokens[i]);
+
+            if (jsonValue instanceof JsonObject) {
+                JsonObject jsonObject = (JsonObject) jsonValue;
+                jsonValue = jsonObject.get(decodedReferenceToken);
+
+                if (jsonValue == null) {
+                    throw new JsonException("The JsonObject " + jsonObject + " contains no value for token " + decodedReferenceToken);
+                }
+            } else if (jsonValue instanceof JsonArray) {
+                JsonArray jsonArray = (JsonArray) jsonValue;
+
+                try {
+                    int index = Integer.parseInt(decodedReferenceToken);
+                    if (index >= jsonArray.size()) {
+                        throw new JsonException("The JsonArray " + jsonArray + " contains no element for index " + index);
+                    }
+                    if (decodedReferenceToken.startsWith("0") && decodedReferenceToken.length() > 1) {
+                        throw new JsonException("The token " + decodedReferenceToken + " with leading zeros is not allowed to reference an element of a JsonArray");
+                    }
+
+                    jsonValue = jsonArray.get(index);
+                } catch (NumberFormatException e) {
+                    throw new JsonException("The token " + decodedReferenceToken + " for the JsonArray " + jsonArray + " is not a number", e);
+                }
+            }
+
+        }
+
+        return jsonValue;
+    }
+
+    /**
+     * Adds or replaces a value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     * <ol>
+     * <li>If the reference is the target (empty JSON Pointer string),
+     * the specified {@code value}, which must be the same type as
+     * specified {@code target}, is returned.</li>
+     * <li>If the reference is an array element, the specified {@code value} is inserted
+     * into the array, at the referenced index. The value currently at that location, and
+     * any subsequent values, are shifted to the right (adds one to the indices).
+     * Index starts with 0. If the reference is specified with a "-", or if the
+     * index is equal to the size of the array, the value is appended to the array.</li>
+     * <li>If the reference is a name/value pair of a {@code JsonObject}, and the
+     * referenced value exists, the value is replaced by the specified {@code value}.
+     * If the value does not exist, a new name/value pair is added to the object.</li>
+     * </ol>
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be added
+     * @return the transformed {@code target} after the value is added.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the reference is an array element and
+     *                              the index is out of range ({@code index < 0 || index > array size}),
+     *                              or if the pointer contains references to non-existing objects or arrays.
+     */
+    public JsonStructure add(JsonStructure target, JsonValue value) {
+        return null;
+    }
+
+    /**
+     * Replaces the value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be stored at the referenced location
+     * @return the transformed {@code target} after the value is replaced.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     */
+    public JsonStructure replace(JsonStructure target, JsonValue value) {
+        return null;
+    }
+
+    /**
+     * Removes the value at the reference location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the transformed {@code target} after the value is removed.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     */
+    public JsonStructure remove(JsonStructure target) {
+        return null;
+    }
+
+    /**
+     * Adds or replaces a value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be added
+     * @return the transformed {@code target} after the value is added.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the reference is an array element and
+     *                              the index is out of range ({@code index < 0 || index > array size}),
+     *                              or if the pointer contains references to non-existing objects or arrays.
+     * @see #add(JsonStructure, JsonValue)
+     */
+    public JsonObject add(JsonObject target, JsonValue value) {
+        return (JsonObject) this.add((JsonStructure) target, value);
+    }
+
+    /**
+     * Adds or replaces a value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be added
+     * @return the transformed {@code target} after the value is added.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the reference is an array element and
+     *                              the index is out of range ({@code index < 0 || index > array size}),
+     *                              or if the pointer contains references to non-existing objects or arrays.
+     * @see #add(JsonStructure, JsonValue)
+     */
+    public JsonArray add(JsonArray target, JsonValue value) {
+        return (JsonArray) this.add((JsonStructure) target, value);
+    }
+
+    /**
+     * Replaces the value at the referenced location in the specified
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be stored at the referenced location
+     * @return the transformed {@code target} after the value is replaced.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     *                              {@code target} with the specified {@code value}.
+     * @see #replace(JsonStructure, JsonValue)
+     */
+    public JsonObject replace(JsonObject target, JsonValue value) {
+        return (JsonObject) this.replace((JsonStructure) target, value);
+    }
+
+    /**
+     * Replaces the value at the referenced location in the specified
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be stored at the referenced location
+     * @return the transformed {@code target} after the value is replaced.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     *                              {@code target} with the specified {@code value}.
+     * @see #replace(JsonStructure, JsonValue)
+     */
+    public JsonArray replace(JsonArray target, JsonValue value) {
+        return (JsonArray) this.replace((JsonStructure) target, value);
+    }
+
+    /**
+     * Removes the value at the reference location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the transformed {@code target} after the value is removed.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     * @see #remove(JsonStructure)
+     */
+    public JsonObject remove(JsonObject target) {
+        return (JsonObject) this.remove((JsonStructure) target);
+    }
+
+    /**
+     * Removes the value at the reference location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the transformed {@code target} after the value is removed.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     * @see #remove(JsonStructure)
+     */
+    public JsonArray remove(JsonArray target) {
+        return (JsonArray) this.remove((JsonStructure) target);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/johnzon/blob/45faea0e/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
new file mode 100644
index 0000000..7750ba6
--- /dev/null
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
@@ -0,0 +1,197 @@
+/*
+ * 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 org.junit.Test;
+
+import javax.json.Json;
+import javax.json.JsonException;
+import javax.json.JsonReader;
+import javax.json.JsonStructure;
+import javax.json.JsonValue;
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+
+public class JsonPointerTest {
+
+    @Test(expected = NullPointerException.class)
+    public void testConstructorWithNullShouldThrowNullPointerException() {
+        new JsonPointer(null);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testConstructorWithInvalidJsonPointerShouldThrowJsonException() {
+        new JsonPointer("a");
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testGetValueWithNullShouldThrowNullPointerException() {
+        JsonPointer jsonPointer = new JsonPointer("");
+        jsonPointer.getValue(null);
+    }
+
+    @Test
+    public void testGetValueWholeDocument() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals(jsonDocument.toString(), result.toString());
+    }
+
+    @Test
+    public void testGetValue0() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("0", result.toString());
+    }
+
+    @Test
+    public void testGetValue1() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/a~1b");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("1", result.toString());
+    }
+
+    @Test
+    public void testGetValue2() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/c%d");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("2", result.toString());
+    }
+
+    @Test
+    public void testGetValue3() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/e^f");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("3", result.toString());
+    }
+
+    @Test
+    public void testGetValue4() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/g|h");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("4", result.toString());
+    }
+
+    @Test
+    public void testGetValue5() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/i\\j");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("5", result.toString());
+    }
+
+    @Test
+    public void testGetValue6() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/k\"l");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("6", result.toString());
+    }
+
+    @Test
+    public void testGetValue7() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/ ");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("7", result.toString());
+    }
+
+    @Test
+    public void testGetValue8() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/m~0n");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("8", result.toString());
+    }
+
+    @Test(expected = JsonException.class)
+    public void testGetValueElementNotExistentShouldThrowJsonException() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/fool");
+        jsonPointer.getValue(jsonDocument);
+    }
+
+    @Test
+    public void testGetValueWholeJsonArray() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/foo");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("[\"bar\",\"baz\"]", result.toString());
+    }
+
+    @Test
+    public void testGetValueJsonArrayElement() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/foo/0");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("\"bar\"", result.toString());
+    }
+
+    @Test(expected = JsonException.class)
+    public void testGetValueJsonArrayElementNotExistentShouldThrowJsonException() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/foo/2");
+        jsonPointer.getValue(jsonDocument);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testGetValueJsonArrayElementNoNumberShouldThrowJsonException() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/foo/a");
+        jsonPointer.getValue(jsonDocument);
+    }
+
+    @Test(expected = JsonException.class)
+    public void testGetValueJsonArrayElementLeadingZeroShouldThrowJsonException() {
+        JsonStructure jsonDocument = getJsonDocument();
+
+        JsonPointer jsonPointer = new JsonPointer("/foo/001");
+        JsonValue result = jsonPointer.getValue(jsonDocument);
+        assertEquals("\"bar\"", result.toString());
+    }
+
+    private JsonStructure getJsonDocument() {
+        JsonReader reader = Json.createReaderFactory(Collections.<String, Object>emptyMap()).createReader(
+                Thread.currentThread().getContextClassLoader().getResourceAsStream("json/jsonPointerTest.json"));
+        return reader.read();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/johnzon/blob/45faea0e/johnzon-core/src/test/resources/json/jsonPointerTest.json
----------------------------------------------------------------------
diff --git a/johnzon-core/src/test/resources/json/jsonPointerTest.json b/johnzon-core/src/test/resources/json/jsonPointerTest.json
new file mode 100644
index 0000000..8cdc1c9
--- /dev/null
+++ b/johnzon-core/src/test/resources/json/jsonPointerTest.json
@@ -0,0 +1,15 @@
+{
+  "foo": [
+    "bar",
+    "baz"
+  ],
+  "": 0,
+  "a/b": 1,
+  "c%d": 2,
+  "e^f": 3,
+  "g|h": 4,
+  "i\\j": 5,
+  "k\"l": 6,
+  " ": 7,
+  "m~n": 8
+}
\ No newline at end of file


[6/6] johnzon git commit: JOHNZON-95 make JsonPointer an internal class which implements the spec API interface

Posted by st...@apache.org.
JOHNZON-95 make JsonPointer an internal class which implements the spec API interface

txs to Armin Hasler for providing the JsonPointer implementation


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/24b01af8
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/24b01af8
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/24b01af8

Branch: refs/heads/JSONP-1.1
Commit: 24b01af8ebe37aa42fb98c2237edf807d5ec7379
Parents: bfdab10
Author: Mark Struberg <st...@apache.org>
Authored: Tue Nov 22 21:49:32 2016 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Tue Nov 22 21:49:32 2016 +0100

----------------------------------------------------------------------
 .../org/apache/johnzon/core/JsonPointer.java    | 476 -------------------
 .../apache/johnzon/core/JsonPointerImpl.java    | 456 ++++++++++++++++++
 .../apache/johnzon/core/JsonProviderImpl.java   |   2 +-
 .../apache/johnzon/core/JsonPointerTest.java    | 124 ++---
 4 files changed, 519 insertions(+), 539 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/24b01af8/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
deleted file mode 100644
index ca942ef..0000000
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointer.java
+++ /dev/null
@@ -1,476 +0,0 @@
-/*
- * 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.Json;
-import javax.json.JsonArray;
-import javax.json.JsonArrayBuilder;
-import javax.json.JsonException;
-import javax.json.JsonObject;
-import javax.json.JsonObjectBuilder;
-import javax.json.JsonStructure;
-import javax.json.JsonValue;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * <p>This class is an immutable representation of a JSON Pointer as specified in
- * <a href="http://tools.ietf.org/html/rfc6901">RFC 6901</a>.
- * </p>
- * <p> A JSON Pointer, when applied to a target {@link JsonValue},
- * defines a reference location in the target.</p>
- * <p> An empty JSON Pointer string defines a reference to the target itself.</p>
- * <p> If the JSON Pointer string is non-empty, it must be a sequence
- * of '/' prefixed tokens, and the target must either be a {@link JsonArray}
- * or {@link JsonObject}. If the target is a {@code JsonArray}, the pointer
- * defines a reference to an array element, and the last token specifies the index.
- * If the target is a {@link JsonObject}, the pointer defines a reference to a
- * name/value pair, and the last token specifies the name.
- * </p>
- * <p> The method {@link JsonPointer#getValue getValue()} returns the referenced value.
- * The methods {@link JsonPointer#add add()}, {@link JsonPointer#replace replace()},
- * and {@link JsonPointer#remove remove()} executes the operations specified in
- * <a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>. </p>
- *
- * @since 1.1
- */
-
-public class JsonPointer {
-
-    private final String jsonPointer;
-    private final List<String> referenceTokens = new ArrayList<String>();
-    private final String lastReferenceToken;
-
-    /**
-     * Constructs and initializes a JsonPointer.
-     *
-     * @param jsonPointer the JSON Pointer string
-     * @throws NullPointerException if {@code jsonPointer} is {@code null}
-     * @throws JsonException        if {@code jsonPointer} is not a valid JSON Pointer
-     */
-    public JsonPointer(String jsonPointer) {
-        if (jsonPointer == null) {
-            throw new NullPointerException("jsonPointer must not be null");
-        }
-        if (!jsonPointer.equals("") && !jsonPointer.startsWith("/")) {
-            throw new JsonException("A non-empty JsonPointer string must begin with a '/'");
-        }
-
-        this.jsonPointer = jsonPointer;
-        String[] encodedReferenceTokens = jsonPointer.split("/", -1);
-
-        for (String encodedReferenceToken : encodedReferenceTokens) {
-            referenceTokens.add(JsonPointerUtil.decode(encodedReferenceToken));
-        }
-        lastReferenceToken = referenceTokens.get(referenceTokens.size() - 1);
-    }
-
-    /**
-     * Compares this {@code JsonPointer} with another object.
-     *
-     * @param obj the object to compare this {@code JsonPointer} against
-     * @return true if the given object is a {@code JsonPointer} with the same
-     * reference tokens as this one, false otherwise.
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null || getClass() != obj.getClass()) {
-            return false;
-        }
-
-        JsonPointer that = (JsonPointer) obj;
-        return jsonPointer.equals(that.jsonPointer);
-    }
-
-    /**
-     * Returns the hash code value for this {@code JsonPointer} object.
-     * The hash code of this object is defined by the hash codes of it's reference tokens.
-     *
-     * @return the hash code value for this {@code JsonPointer} object
-     */
-    @Override
-    public int hashCode() {
-        return jsonPointer.hashCode();
-    }
-
-    /**
-     * Returns the value at the referenced location in the specified {@code target}
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @return the referenced value in the target.
-     * @throws NullPointerException if {@code target} is null
-     * @throws JsonException        if the referenced value does not exist
-     */
-    public JsonValue getValue(JsonStructure target) {
-        if (target == null) {
-            throw new NullPointerException("target must not be null");
-        }
-        if (isEmptyJsonPointer()) {
-            return target;
-        }
-
-        JsonValue jsonValue = target;
-        for (int i = 1; i < referenceTokens.size(); i++) {
-            jsonValue = getValue(jsonValue, referenceTokens.get(i), i, referenceTokens.size() - 1);
-        }
-        return jsonValue;
-    }
-
-    /**
-     * Adds or replaces a value at the referenced location in the specified
-     * {@code target} with the specified {@code value}.
-     * <ol>
-     * <li>If the reference is the target (empty JSON Pointer string),
-     * the specified {@code value}, which must be the same type as
-     * specified {@code target}, is returned.</li>
-     * <li>If the reference is an array element, the specified {@code value} is inserted
-     * into the array, at the referenced index. The value currently at that location, and
-     * any subsequent values, are shifted to the right (adds one to the indices).
-     * Index starts with 0. If the reference is specified with a "-", or if the
-     * index is equal to the size of the array, the value is appended to the array.</li>
-     * <li>If the reference is a name/value pair of a {@code JsonObject}, and the
-     * referenced value exists, the value is replaced by the specified {@code value}.
-     * If the value does not exist, a new name/value pair is added to the object.</li>
-     * </ol>
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @param value  the value to be added
-     * @return the transformed {@code target} after the value is added.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the reference is an array element and
-     *                              the index is out of range ({@code index < 0 || index > array size}),
-     *                              or if the pointer contains references to non-existing objects or arrays.
-     */
-    public JsonStructure add(JsonStructure target, JsonValue value) {
-        validateAdd(target);
-        if (isEmptyJsonPointer()) {
-            if (value.getClass() != target.getClass()) {
-                throw new JsonException("The value must have the same type as the target");
-            }
-            return (JsonStructure) value;
-        }
-
-        if (target instanceof JsonObject) {
-            return add((JsonObject) target, value);
-        } else {
-            return add((JsonArray) target, value);
-        }
-    }
-
-    /**
-     * Adds or replaces a value at the referenced location in the specified
-     * {@code target} with the specified {@code value}.
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @param value  the value to be added
-     * @return the transformed {@code target} after the value is added.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the reference is an array element and
-     *                              the index is out of range ({@code index < 0 || index > array size}),
-     *                              or if the pointer contains references to non-existing objects or arrays.
-     * @see #add(JsonStructure, JsonValue)
-     */
-    public JsonObject add(JsonObject target, JsonValue value) {
-        validateAdd(target);
-
-        return (JsonObject) add(target, 1, referenceTokens.size() - 1, value);
-    }
-
-    /**
-     * Adds or replaces a value at the referenced location in the specified
-     * {@code target} with the specified {@code value}.
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @param value  the value to be added
-     * @return the transformed {@code target} after the value is added.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the reference is an array element and
-     *                              the index is out of range ({@code index < 0 || index > array size}),
-     *                              or if the pointer contains references to non-existing objects or arrays.
-     * @see #add(JsonStructure, JsonValue)
-     */
-    public JsonArray add(JsonArray target, JsonValue value) {
-        validateAdd(target);
-
-        return (JsonArray) add(target, 1, referenceTokens.size() - 1, value);
-    }
-
-    /**
-     * Replaces the value at the referenced location in the specified
-     * {@code target} with the specified {@code value}.
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @param value  the value to be stored at the referenced location
-     * @return the transformed {@code target} after the value is replaced.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the referenced value does not exist,
-     *                              or if the reference is the target.
-     */
-    public JsonStructure replace(JsonStructure target, JsonValue value) {
-        if (target instanceof JsonObject) {
-            return replace((JsonObject) target, value);
-        } else {
-            return replace((JsonArray) target, value);
-        }
-    }
-
-    /**
-     * Replaces the value at the referenced location in the specified
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @param value  the value to be stored at the referenced location
-     * @return the transformed {@code target} after the value is replaced.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the referenced value does not exist,
-     *                              or if the reference is the target.
-     * @see #replace(JsonStructure, JsonValue)
-     */
-    public JsonObject replace(JsonObject target, JsonValue value) {
-        return add(remove(target), value);
-    }
-
-    /**
-     * Replaces the value at the referenced location in the specified
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @param value  the value to be stored at the referenced location
-     * @return the transformed {@code target} after the value is replaced.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the referenced value does not exist,
-     *                              or if the reference is the target.
-     * @see #replace(JsonStructure, JsonValue)
-     */
-    public JsonArray replace(JsonArray target, JsonValue value) {
-        return add(remove(target), value);
-    }
-
-    /**
-     * Removes the value at the reference location in the specified {@code target}
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @return the transformed {@code target} after the value is removed.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the referenced value does not exist,
-     *                              or if the reference is the target.
-     */
-    public JsonStructure remove(JsonStructure target) {
-        if (target instanceof JsonObject) {
-            return remove((JsonObject) target);
-        } else {
-            return remove((JsonArray) target);
-        }
-    }
-
-    /**
-     * Removes the value at the reference location in the specified {@code target}
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @return the transformed {@code target} after the value is removed.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the referenced value does not exist,
-     *                              or if the reference is the target.
-     * @see #remove(JsonStructure)
-     */
-    public JsonObject remove(JsonObject target) {
-        validateRemove(target);
-
-        return (JsonObject) remove(target, 1, referenceTokens.size() - 1);
-    }
-
-    /**
-     * Removes the value at the reference location in the specified {@code target}
-     *
-     * @param target the target referenced by this {@code JsonPointer}
-     * @return the transformed {@code target} after the value is removed.
-     * @throws NullPointerException if {@code target} is {@code null}
-     * @throws JsonException        if the referenced value does not exist,
-     *                              or if the reference is the target.
-     * @see #remove(JsonStructure)
-     */
-    public JsonArray remove(JsonArray target) {
-        validateRemove(target);
-
-        return (JsonArray) remove(target, 1, referenceTokens.size() - 1);
-    }
-
-    private void validateAdd(JsonValue target) {
-        validateJsonPointer(target, referenceTokens.size() - 1);
-    }
-
-    private void validateRemove(JsonValue target) {
-        validateJsonPointer(target, referenceTokens.size());
-        if (isEmptyJsonPointer()) {
-            throw new JsonException("The reference must not be the target");
-        }
-    }
-
-    private boolean isEmptyJsonPointer() {
-        return jsonPointer.equals("");
-    }
-
-    private JsonValue getValue(JsonValue jsonValue, String referenceToken, int currentPosition, int referencePosition) {
-        if (jsonValue instanceof JsonObject) {
-            JsonObject jsonObject = (JsonObject) jsonValue;
-            jsonValue = jsonObject.get(referenceToken);
-
-            if (jsonValue != null) {
-                return jsonValue;
-            }
-            throw new JsonException("'" + jsonObject + "' contains no value for name '" + referenceToken + "'");
-        } else if (jsonValue instanceof JsonArray) {
-            validateArrayIndex(referenceToken);
-
-            try {
-                JsonArray jsonArray = (JsonArray) jsonValue;
-                int arrayIndex = Integer.parseInt(referenceToken);
-                validateArraySize(jsonArray, arrayIndex, jsonArray.size());
-                return jsonArray.get(arrayIndex);
-            } catch (NumberFormatException e) {
-                throw new JsonException("'" + referenceToken + "' is no valid array index", e);
-            }
-        } else {
-            if (currentPosition != referencePosition) {
-                return jsonValue;
-            }
-            throw new JsonException("'" + jsonValue + "' contains no element for '" + referenceToken + "'");
-        }
-    }
-
-    private JsonValue add(JsonValue jsonValue, int currentPosition, int referencePosition, JsonValue newValue) {
-        if (jsonValue instanceof JsonObject) {
-            JsonObject jsonObject = (JsonObject) jsonValue;
-            JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
-
-            if (jsonObject.isEmpty()) {
-                objectBuilder.add(lastReferenceToken, newValue);
-            } else {
-                for (Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
-                    objectBuilder.add(entry.getKey(), add(entry.getValue(), currentPosition + 1, referencePosition, newValue));
-                    if (currentPosition == referencePosition) {
-                        objectBuilder.add(lastReferenceToken, newValue);
-                    }
-                }
-            }
-            return objectBuilder.build();
-        } else if (jsonValue instanceof JsonArray) {
-            JsonArray jsonArray = (JsonArray) jsonValue;
-            JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
-
-            int arrayIndex = -1;
-            if (currentPosition == referencePosition) {
-                arrayIndex = getArrayIndex(lastReferenceToken, jsonArray, true);
-            }
-
-            int jsonArraySize = jsonArray.size();
-            for (int i = 0; i <= jsonArraySize; i++) {
-                if (i == arrayIndex) {
-                    arrayBuilder.add(newValue);
-                }
-                if (i == jsonArraySize) {
-                    break;
-                }
-                arrayBuilder.add(add(jsonArray.get(i), currentPosition + 1, referencePosition, newValue));
-            }
-            return arrayBuilder.build();
-        }
-        return jsonValue;
-    }
-
-    private JsonValue remove(JsonValue jsonValue, int currentPosition, int referencePosition) {
-        if (jsonValue instanceof JsonObject) {
-            JsonObject jsonObject = (JsonObject) jsonValue;
-            JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
-
-            for (Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
-                if (currentPosition == referencePosition
-                        && lastReferenceToken.equals(entry.getKey())) {
-                    continue;
-                }
-                objectBuilder.add(entry.getKey(), remove(entry.getValue(), currentPosition + 1, referencePosition));
-            }
-            return objectBuilder.build();
-        } else if (jsonValue instanceof JsonArray) {
-            JsonArray jsonArray = (JsonArray) jsonValue;
-            JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
-
-            int arrayIndex = -1;
-            if (currentPosition == referencePosition) {
-                arrayIndex = getArrayIndex(lastReferenceToken, jsonArray, false);
-            }
-
-            int jsonArraySize = jsonArray.size();
-            for (int i = 0; i < jsonArraySize; i++) {
-                if (i == arrayIndex) {
-                    continue;
-                }
-                arrayBuilder.add(remove(jsonArray.get(i), currentPosition + 1, referencePosition));
-            }
-            return arrayBuilder.build();
-        }
-        return jsonValue;
-    }
-
-    private int getArrayIndex(String referenceToken, JsonArray jsonArray, boolean addOperation) {
-        if (addOperation && referenceToken.equals("-")) {
-            return jsonArray.size();
-        }
-
-        validateArrayIndex(referenceToken);
-
-        try {
-            int arrayIndex = Integer.parseInt(referenceToken);
-            int arraySize = addOperation ? jsonArray.size() + 1 : jsonArray.size();
-            validateArraySize(jsonArray, arrayIndex, arraySize);
-            return arrayIndex;
-        } catch (NumberFormatException e) {
-            throw new JsonException("'" + referenceToken + "' is no valid array index", e);
-        }
-    }
-
-    private void validateJsonPointer(JsonValue target, int size) throws NullPointerException, JsonException {
-        if (target == null) {
-            throw new NullPointerException("target must not be null");
-        }
-
-        JsonValue jsonValue = target;
-        for (int i = 1; i < size; i++) {
-            jsonValue = getValue(jsonValue, referenceTokens.get(i), i, referenceTokens.size() - 1);
-        }
-    }
-
-    private void validateArrayIndex(String referenceToken) throws JsonException {
-        if (referenceToken.startsWith("+") || referenceToken.startsWith("-")) {
-            throw new JsonException("An array index must not start with '" + referenceToken.charAt(0) + "'");
-        }
-        if (referenceToken.startsWith("0") && referenceToken.length() > 1) {
-            throw new JsonException("An array index must not start with a leading '0'");
-        }
-    }
-
-    private void validateArraySize(JsonArray jsonArray, int arrayIndex, int arraySize) throws JsonException {
-        if (arrayIndex >= arraySize) {
-            throw new JsonException("'" + jsonArray + "' contains no element for index " + arrayIndex);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/johnzon/blob/24b01af8/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerImpl.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerImpl.java
new file mode 100644
index 0000000..25e5ceb
--- /dev/null
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonPointerImpl.java
@@ -0,0 +1,456 @@
+/*
+ * 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.Json;
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+import javax.json.JsonPointer;
+import javax.json.JsonStructure;
+import javax.json.JsonValue;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+public class JsonPointerImpl implements JsonPointer {
+
+    private final String jsonPointer;
+    private final List<String> referenceTokens = new ArrayList<String>();
+    private final String lastReferenceToken;
+
+    /**
+     * Constructs and initializes a JsonPointer.
+     *
+     * @param jsonPointer the JSON Pointer string
+     * @throws NullPointerException if {@code jsonPointer} is {@code null}
+     * @throws JsonException        if {@code jsonPointer} is not a valid JSON Pointer
+     */
+    public JsonPointerImpl(String jsonPointer) {
+        if (jsonPointer == null) {
+            throw new NullPointerException("jsonPointer must not be null");
+        }
+        if (!jsonPointer.equals("") && !jsonPointer.startsWith("/")) {
+            throw new JsonException("A non-empty JsonPointer string must begin with a '/'");
+        }
+
+        this.jsonPointer = jsonPointer;
+        String[] encodedReferenceTokens = jsonPointer.split("/", -1);
+
+        for (String encodedReferenceToken : encodedReferenceTokens) {
+            referenceTokens.add(JsonPointerUtil.decode(encodedReferenceToken));
+        }
+        lastReferenceToken = referenceTokens.get(referenceTokens.size() - 1);
+    }
+
+    /**
+     * Compares this {@code JsonPointer} with another object.
+     *
+     * @param obj the object to compare this {@code JsonPointer} against
+     * @return true if the given object is a {@code JsonPointer} with the same
+     * reference tokens as this one, false otherwise.
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+
+        JsonPointerImpl that = (JsonPointerImpl) obj;
+        return jsonPointer.equals(that.jsonPointer);
+    }
+
+    /**
+     * Returns the hash code value for this {@code JsonPointer} object.
+     * The hash code of this object is defined by the hash codes of it's reference tokens.
+     *
+     * @return the hash code value for this {@code JsonPointer} object
+     */
+    @Override
+    public int hashCode() {
+        return jsonPointer.hashCode();
+    }
+
+    /**
+     * Returns the value at the referenced location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the referenced value in the target.
+     * @throws NullPointerException if {@code target} is null
+     * @throws JsonException        if the referenced value does not exist
+     */
+    public JsonValue getValue(JsonStructure target) {
+        if (target == null) {
+            throw new NullPointerException("target must not be null");
+        }
+        if (isEmptyJsonPointer()) {
+            return target;
+        }
+
+        JsonValue jsonValue = target;
+        for (int i = 1; i < referenceTokens.size(); i++) {
+            jsonValue = getValue(jsonValue, referenceTokens.get(i), i, referenceTokens.size() - 1);
+        }
+        return jsonValue;
+    }
+
+    /**
+     * Adds or replaces a value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     * <ol>
+     * <li>If the reference is the target (empty JSON Pointer string),
+     * the specified {@code value}, which must be the same type as
+     * specified {@code target}, is returned.</li>
+     * <li>If the reference is an array element, the specified {@code value} is inserted
+     * into the array, at the referenced index. The value currently at that location, and
+     * any subsequent values, are shifted to the right (adds one to the indices).
+     * Index starts with 0. If the reference is specified with a "-", or if the
+     * index is equal to the size of the array, the value is appended to the array.</li>
+     * <li>If the reference is a name/value pair of a {@code JsonObject}, and the
+     * referenced value exists, the value is replaced by the specified {@code value}.
+     * If the value does not exist, a new name/value pair is added to the object.</li>
+     * </ol>
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be added
+     * @return the transformed {@code target} after the value is added.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the reference is an array element and
+     *                              the index is out of range ({@code index < 0 || index > array size}),
+     *                              or if the pointer contains references to non-existing objects or arrays.
+     */
+    public JsonStructure add(JsonStructure target, JsonValue value) {
+        validateAdd(target);
+        if (isEmptyJsonPointer()) {
+            if (value.getClass() != target.getClass()) {
+                throw new JsonException("The value must have the same type as the target");
+            }
+            return (JsonStructure) value;
+        }
+
+        if (target instanceof JsonObject) {
+            return add((JsonObject) target, value);
+        } else {
+            return add((JsonArray) target, value);
+        }
+    }
+
+    /**
+     * Adds or replaces a value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be added
+     * @return the transformed {@code target} after the value is added.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the reference is an array element and
+     *                              the index is out of range ({@code index < 0 || index > array size}),
+     *                              or if the pointer contains references to non-existing objects or arrays.
+     * @see #add(JsonStructure, JsonValue)
+     */
+    public JsonObject add(JsonObject target, JsonValue value) {
+        validateAdd(target);
+
+        return (JsonObject) add(target, 1, referenceTokens.size() - 1, value);
+    }
+
+    /**
+     * Adds or replaces a value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be added
+     * @return the transformed {@code target} after the value is added.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the reference is an array element and
+     *                              the index is out of range ({@code index < 0 || index > array size}),
+     *                              or if the pointer contains references to non-existing objects or arrays.
+     * @see #add(JsonStructure, JsonValue)
+     */
+    public JsonArray add(JsonArray target, JsonValue value) {
+        validateAdd(target);
+
+        return (JsonArray) add(target, 1, referenceTokens.size() - 1, value);
+    }
+
+    /**
+     * Replaces the value at the referenced location in the specified
+     * {@code target} with the specified {@code value}.
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be stored at the referenced location
+     * @return the transformed {@code target} after the value is replaced.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     */
+    public JsonStructure replace(JsonStructure target, JsonValue value) {
+        if (target instanceof JsonObject) {
+            return replace((JsonObject) target, value);
+        } else {
+            return replace((JsonArray) target, value);
+        }
+    }
+
+    /**
+     * Replaces the value at the referenced location in the specified
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be stored at the referenced location
+     * @return the transformed {@code target} after the value is replaced.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     * @see #replace(JsonStructure, JsonValue)
+     */
+    public JsonObject replace(JsonObject target, JsonValue value) {
+        return add(remove(target), value);
+    }
+
+    /**
+     * Replaces the value at the referenced location in the specified
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @param value  the value to be stored at the referenced location
+     * @return the transformed {@code target} after the value is replaced.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     * @see #replace(JsonStructure, JsonValue)
+     */
+    public JsonArray replace(JsonArray target, JsonValue value) {
+        return add(remove(target), value);
+    }
+
+    /**
+     * Removes the value at the reference location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the transformed {@code target} after the value is removed.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     */
+    public JsonStructure remove(JsonStructure target) {
+        if (target instanceof JsonObject) {
+            return remove((JsonObject) target);
+        } else {
+            return remove((JsonArray) target);
+        }
+    }
+
+    /**
+     * Removes the value at the reference location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the transformed {@code target} after the value is removed.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     * @see #remove(JsonStructure)
+     */
+    public JsonObject remove(JsonObject target) {
+        validateRemove(target);
+
+        return (JsonObject) remove(target, 1, referenceTokens.size() - 1);
+    }
+
+    /**
+     * Removes the value at the reference location in the specified {@code target}
+     *
+     * @param target the target referenced by this {@code JsonPointer}
+     * @return the transformed {@code target} after the value is removed.
+     * @throws NullPointerException if {@code target} is {@code null}
+     * @throws JsonException        if the referenced value does not exist,
+     *                              or if the reference is the target.
+     * @see #remove(JsonStructure)
+     */
+    public JsonArray remove(JsonArray target) {
+        validateRemove(target);
+
+        return (JsonArray) remove(target, 1, referenceTokens.size() - 1);
+    }
+
+    private void validateAdd(JsonValue target) {
+        validateJsonPointer(target, referenceTokens.size() - 1);
+    }
+
+    private void validateRemove(JsonValue target) {
+        validateJsonPointer(target, referenceTokens.size());
+        if (isEmptyJsonPointer()) {
+            throw new JsonException("The reference must not be the target");
+        }
+    }
+
+    private boolean isEmptyJsonPointer() {
+        return jsonPointer.equals("");
+    }
+
+    private JsonValue getValue(JsonValue jsonValue, String referenceToken, int currentPosition, int referencePosition) {
+        if (jsonValue instanceof JsonObject) {
+            JsonObject jsonObject = (JsonObject) jsonValue;
+            jsonValue = jsonObject.get(referenceToken);
+
+            if (jsonValue != null) {
+                return jsonValue;
+            }
+            throw new JsonException("'" + jsonObject + "' contains no value for name '" + referenceToken + "'");
+        } else if (jsonValue instanceof JsonArray) {
+            validateArrayIndex(referenceToken);
+
+            try {
+                JsonArray jsonArray = (JsonArray) jsonValue;
+                int arrayIndex = Integer.parseInt(referenceToken);
+                validateArraySize(jsonArray, arrayIndex, jsonArray.size());
+                return jsonArray.get(arrayIndex);
+            } catch (NumberFormatException e) {
+                throw new JsonException("'" + referenceToken + "' is no valid array index", e);
+            }
+        } else {
+            if (currentPosition != referencePosition) {
+                return jsonValue;
+            }
+            throw new JsonException("'" + jsonValue + "' contains no element for '" + referenceToken + "'");
+        }
+    }
+
+    private JsonValue add(JsonValue jsonValue, int currentPosition, int referencePosition, JsonValue newValue) {
+        if (jsonValue instanceof JsonObject) {
+            JsonObject jsonObject = (JsonObject) jsonValue;
+            JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
+
+            if (jsonObject.isEmpty()) {
+                objectBuilder.add(lastReferenceToken, newValue);
+            } else {
+                for (Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
+                    objectBuilder.add(entry.getKey(), add(entry.getValue(), currentPosition + 1, referencePosition, newValue));
+                    if (currentPosition == referencePosition) {
+                        objectBuilder.add(lastReferenceToken, newValue);
+                    }
+                }
+            }
+            return objectBuilder.build();
+        } else if (jsonValue instanceof JsonArray) {
+            JsonArray jsonArray = (JsonArray) jsonValue;
+            JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
+
+            int arrayIndex = -1;
+            if (currentPosition == referencePosition) {
+                arrayIndex = getArrayIndex(lastReferenceToken, jsonArray, true);
+            }
+
+            int jsonArraySize = jsonArray.size();
+            for (int i = 0; i <= jsonArraySize; i++) {
+                if (i == arrayIndex) {
+                    arrayBuilder.add(newValue);
+                }
+                if (i == jsonArraySize) {
+                    break;
+                }
+                arrayBuilder.add(add(jsonArray.get(i), currentPosition + 1, referencePosition, newValue));
+            }
+            return arrayBuilder.build();
+        }
+        return jsonValue;
+    }
+
+    private JsonValue remove(JsonValue jsonValue, int currentPosition, int referencePosition) {
+        if (jsonValue instanceof JsonObject) {
+            JsonObject jsonObject = (JsonObject) jsonValue;
+            JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
+
+            for (Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
+                if (currentPosition == referencePosition
+                        && lastReferenceToken.equals(entry.getKey())) {
+                    continue;
+                }
+                objectBuilder.add(entry.getKey(), remove(entry.getValue(), currentPosition + 1, referencePosition));
+            }
+            return objectBuilder.build();
+        } else if (jsonValue instanceof JsonArray) {
+            JsonArray jsonArray = (JsonArray) jsonValue;
+            JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
+
+            int arrayIndex = -1;
+            if (currentPosition == referencePosition) {
+                arrayIndex = getArrayIndex(lastReferenceToken, jsonArray, false);
+            }
+
+            int jsonArraySize = jsonArray.size();
+            for (int i = 0; i < jsonArraySize; i++) {
+                if (i == arrayIndex) {
+                    continue;
+                }
+                arrayBuilder.add(remove(jsonArray.get(i), currentPosition + 1, referencePosition));
+            }
+            return arrayBuilder.build();
+        }
+        return jsonValue;
+    }
+
+    private int getArrayIndex(String referenceToken, JsonArray jsonArray, boolean addOperation) {
+        if (addOperation && referenceToken.equals("-")) {
+            return jsonArray.size();
+        }
+
+        validateArrayIndex(referenceToken);
+
+        try {
+            int arrayIndex = Integer.parseInt(referenceToken);
+            int arraySize = addOperation ? jsonArray.size() + 1 : jsonArray.size();
+            validateArraySize(jsonArray, arrayIndex, arraySize);
+            return arrayIndex;
+        } catch (NumberFormatException e) {
+            throw new JsonException("'" + referenceToken + "' is no valid array index", e);
+        }
+    }
+
+    private void validateJsonPointer(JsonValue target, int size) throws NullPointerException, JsonException {
+        if (target == null) {
+            throw new NullPointerException("target must not be null");
+        }
+
+        JsonValue jsonValue = target;
+        for (int i = 1; i < size; i++) {
+            jsonValue = getValue(jsonValue, referenceTokens.get(i), i, referenceTokens.size() - 1);
+        }
+    }
+
+    private void validateArrayIndex(String referenceToken) throws JsonException {
+        if (referenceToken.startsWith("+") || referenceToken.startsWith("-")) {
+            throw new JsonException("An array index must not start with '" + referenceToken.charAt(0) + "'");
+        }
+        if (referenceToken.startsWith("0") && referenceToken.length() > 1) {
+            throw new JsonException("An array index must not start with a leading '0'");
+        }
+    }
+
+    private void validateArraySize(JsonArray jsonArray, int arrayIndex, int arraySize) throws JsonException {
+        if (arrayIndex >= arraySize) {
+            throw new JsonException("'" + jsonArray + "' contains no element for index " + arrayIndex);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/johnzon/blob/24b01af8/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java
index 99fd6fc..e9926f9 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonProviderImpl.java
@@ -236,7 +236,7 @@ public class JsonProviderImpl extends JsonProvider implements Serializable {
 
         @Override
         public JsonPointer createJsonPointer(String path) {
-            throw new UnsupportedOperationException("TODO JSON-P 1.1");
+            return new JsonPointerImpl(path);
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/johnzon/blob/24b01af8/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
index 9b6c722..7a3d32a 100644
--- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonPointerTest.java
@@ -37,17 +37,17 @@ public class JsonPointerTest {
 
     @Test(expected = NullPointerException.class)
     public void testConstructorWithJsonPointerNull() {
-        new JsonPointer(null);
+        new JsonPointerImpl(null);
     }
 
     @Test(expected = JsonException.class)
     public void testConstructorWithInvalidJsonPointer() {
-        new JsonPointer("a");
+        new JsonPointerImpl("a");
     }
 
     @Test(expected = NullPointerException.class)
     public void testGetValueWithTargetNull() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         jsonPointer.getValue(null);
     }
 
@@ -55,7 +55,7 @@ public class JsonPointerTest {
     public void testGetValueWithWholeDocument() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals(jsonDocument.toString(), result.toString());
     }
@@ -64,7 +64,7 @@ public class JsonPointerTest {
     public void testGetValue0() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("0", result.toString());
     }
@@ -73,7 +73,7 @@ public class JsonPointerTest {
     public void testGetValue1() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/a~1b");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/a~1b");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("1", result.toString());
     }
@@ -82,7 +82,7 @@ public class JsonPointerTest {
     public void testGetValue2() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/c%d");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/c%d");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("2", result.toString());
     }
@@ -91,7 +91,7 @@ public class JsonPointerTest {
     public void testGetValue3() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/e^f");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/e^f");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("3", result.toString());
     }
@@ -100,7 +100,7 @@ public class JsonPointerTest {
     public void testGetValue4() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/g|h");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/g|h");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("4", result.toString());
     }
@@ -109,7 +109,7 @@ public class JsonPointerTest {
     public void testGetValue5() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/i\\j");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/i\\j");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("5", result.toString());
     }
@@ -118,7 +118,7 @@ public class JsonPointerTest {
     public void testGetValue6() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/k\"l");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/k\"l");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("6", result.toString());
     }
@@ -127,7 +127,7 @@ public class JsonPointerTest {
     public void testGetValue7() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/ ");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/ ");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("7", result.toString());
     }
@@ -136,7 +136,7 @@ public class JsonPointerTest {
     public void testGetValue8() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/m~0n");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/m~0n");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("8", result.toString());
     }
@@ -145,7 +145,7 @@ public class JsonPointerTest {
     public void testGetValueWithElementNotExistent() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/fool");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/fool");
         jsonPointer.getValue(jsonDocument);
     }
 
@@ -153,7 +153,7 @@ public class JsonPointerTest {
     public void testGetValueWithWholeJsonArray() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/foo");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("[\"bar\",\"baz\"]", result.toString());
     }
@@ -162,7 +162,7 @@ public class JsonPointerTest {
     public void testGetValueWithJsonArray() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/foo/0");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/0");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("\"bar\"", result.toString());
     }
@@ -171,7 +171,7 @@ public class JsonPointerTest {
     public void testGetValueWithJsonArrayIndexOutOfRange() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/foo/2");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/2");
         jsonPointer.getValue(jsonDocument);
     }
 
@@ -179,7 +179,7 @@ public class JsonPointerTest {
     public void testGetValueWithJsonArrayIndexNoNumber() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/foo/a");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/a");
         jsonPointer.getValue(jsonDocument);
     }
 
@@ -187,7 +187,7 @@ public class JsonPointerTest {
     public void testGetValueWithJsonArrayLeadingZeroIndex() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/foo/01");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/01");
         JsonValue result = jsonPointer.getValue(jsonDocument);
         assertEquals("\"bar\"", result.toString());
     }
@@ -196,19 +196,19 @@ public class JsonPointerTest {
     public void testGetValueWithJsonArrayInvalidIndex() {
         JsonStructure jsonDocument = getJsonDocument();
 
-        JsonPointer jsonPointer = new JsonPointer("/foo/-1");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/-1");
         jsonPointer.getValue(jsonDocument);
     }
 
     @Test(expected = NullPointerException.class)
     public void testAddJsonStructureWithTargetNull() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         jsonPointer.add((JsonStructure) null, new JsonStringImpl("qux"));
     }
 
     @Test(expected = JsonException.class)
     public void testAddJsonStructureWithTypeValueNotTypeTarget() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         JsonObject target = Json.createObjectBuilder().build();
         JsonArray value = Json.createArrayBuilder().build();
 
@@ -217,7 +217,7 @@ public class JsonPointerTest {
 
     @Test
     public void testAddJsonStructureWithEmptyJsonPointer() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         JsonStructure target = Json.createObjectBuilder().build();
         JsonObject value = Json.createObjectBuilder()
                 .add("foo", "bar").build(); // { "foo": "bar" }
@@ -228,19 +228,19 @@ public class JsonPointerTest {
 
     @Test(expected = NullPointerException.class)
     public void testAddJsonObjectWithTargetNull() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         jsonPointer.add((JsonObject) null, new JsonStringImpl("qux"));
     }
 
     @Test(expected = NullPointerException.class)
     public void testAddJsonArrayWithTargetNull() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         jsonPointer.add((JsonArray) null, new JsonStringImpl("qux"));
     }
 
     @Test(expected = JsonException.class)
     public void testAddArrayElementWithInvalidIndex() {
-        JsonPointer jsonPointer = new JsonPointer("/+");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/+");
         JsonStructure target = Json.createArrayBuilder().build();
 
         jsonPointer.add(target, new JsonStringImpl("qux"));
@@ -248,7 +248,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testAddArrayElementWithIndexOutOfRange() {
-        JsonPointer jsonPointer = new JsonPointer("/1");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/1");
         JsonStructure target = Json.createArrayBuilder().build();
 
         jsonPointer.add(target, new JsonStringImpl("qux"));
@@ -256,7 +256,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testAddArrayElementWithLeadingZeroIndex() {
-        JsonPointer jsonPointer = new JsonPointer("/01");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/01");
         JsonStructure target = Json.createArrayBuilder()
                 .add("foo").build();
 
@@ -265,7 +265,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testAddArrayElementWithIndexNoNumber() {
-        JsonPointer jsonPointer = new JsonPointer("/a");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/a");
         JsonStructure target = Json.createArrayBuilder()
                 .add("foo").build();
 
@@ -274,7 +274,7 @@ public class JsonPointerTest {
 
     @Test
     public void testAddObject() {
-        JsonPointer jsonPointer = new JsonPointer("/child");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/child");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", "bar").build(); // {"foo":"bar"}
         JsonObject value = Json.createObjectBuilder()
@@ -286,7 +286,7 @@ public class JsonPointerTest {
 
     @Test
     public void testAddObjectMember() {
-        JsonPointer jsonPointer = new JsonPointer("/baz");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/baz");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", "bar").build(); // {"foo":"bar"}
 
@@ -296,7 +296,7 @@ public class JsonPointerTest {
 
     @Test
     public void testAddFirstObjectMember() {
-        JsonPointer jsonPointer = new JsonPointer("/foo");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo");
         JsonStructure target = Json.createObjectBuilder().build(); // {}
 
         JsonStructure result = jsonPointer.add(target, new JsonStringImpl("bar"));
@@ -305,7 +305,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testAddObjectMemberWithNonexistentTarget() {
-        JsonPointer jsonPointer = new JsonPointer("/baz/bat");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/baz/bat");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", "bar").build(); // {"foo":"bar"}
 
@@ -314,7 +314,7 @@ public class JsonPointerTest {
 
     @Test
     public void testAddReplaceObjectMember() {
-        JsonPointer jsonPointer = new JsonPointer("/baz");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/baz");
         JsonStructure target = Json.createObjectBuilder()
                 .add("baz", "qux")
                 .add("foo", "bar").build(); // {"baz":"qux","foo":"bar"}
@@ -325,7 +325,7 @@ public class JsonPointerTest {
 
     @Test
     public void testAddArray() {
-        JsonPointer jsonPointer = new JsonPointer("/0/-");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/0/-");
         JsonStructure target = Json.createArrayBuilder()
                 .add(Json.createArrayBuilder()
                         .add("bar")).build(); // [["bar"]]
@@ -339,7 +339,7 @@ public class JsonPointerTest {
 
     @Test
     public void testAddArrayElement() {
-        JsonPointer jsonPointer = new JsonPointer("/foo/1");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/1");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", Json.createArrayBuilder()
                         .add("bar")
@@ -351,13 +351,13 @@ public class JsonPointerTest {
 
     @Test(expected = NullPointerException.class)
     public void testRemoveJsonObjectWithTargetNull() {
-        JsonPointer jsonPointer = new JsonPointer("/");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/");
         jsonPointer.remove((JsonObject) null);
     }
 
     @Test(expected = JsonException.class)
     public void testRemoveJsonObjectWithEmptyJsonPointer() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         JsonObject target = Json.createObjectBuilder().build();
 
         jsonPointer.remove(target);
@@ -365,13 +365,13 @@ public class JsonPointerTest {
 
     @Test(expected = NullPointerException.class)
     public void testRemoveJsonArrayWithTargetNull() {
-        JsonPointer jsonPointer = new JsonPointer("/");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/");
         jsonPointer.remove((JsonArray) null);
     }
 
     @Test(expected = JsonException.class)
     public void testRemoveJsonArrayWithEmptyJsonPointer() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         JsonArray target = Json.createArrayBuilder().build();
 
         jsonPointer.remove(target);
@@ -379,7 +379,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testRemoveArrayElementWithIndexNoNumber() {
-        JsonPointer jsonPointer = new JsonPointer("/foo/a");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/a");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", Json.createArrayBuilder()
                         .add("bar")
@@ -391,7 +391,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testRemoveArrayElementWithIndexOutOfRange() {
-        JsonPointer jsonPointer = new JsonPointer("/foo/3");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/3");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", Json.createArrayBuilder()
                         .add("bar")
@@ -403,7 +403,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testRemoveArrayElementWithInvalidIndex() {
-        JsonPointer jsonPointer = new JsonPointer("/foo/+");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/+");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", Json.createArrayBuilder()
                         .add("bar")
@@ -415,7 +415,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testRemoveArrayElementWithLeadingZeroIndex() {
-        JsonPointer jsonPointer = new JsonPointer("/foo/01");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/foo/01");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", Json.createArrayBuilder()
                         .add("bar")
@@ -427,7 +427,7 @@ public class JsonPointerTest {
 
     @Test
     public void testRemoveArrayElement() {
-        JsonPointer jsonPointer = new JsonPointer("/0/1");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/0/1");
         JsonStructure target = Json.createArrayBuilder()
                 .add(Json.createArrayBuilder()
                         .add("bar")
@@ -440,7 +440,7 @@ public class JsonPointerTest {
 
     @Test
     public void testRemoveObjectMember() {
-        JsonPointer jsonPointer = new JsonPointer("/baz");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/baz");
         JsonStructure target = Json.createObjectBuilder()
                 .add("baz", "qux")
                 .add("foo", "bar").build(); // {"baz":"qux","foo":"bar"}
@@ -451,13 +451,13 @@ public class JsonPointerTest {
 
     @Test(expected = NullPointerException.class)
     public void testReplaceJsonObjectWithTargetNull() {
-        JsonPointer jsonPointer = new JsonPointer("/");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/");
         jsonPointer.replace((JsonObject) null, new JsonStringImpl("qux"));
     }
 
     @Test(expected = JsonException.class)
     public void testReplaceJsonObjectWithEmptyJsonPointer() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         JsonObject target = Json.createObjectBuilder().build();
 
         jsonPointer.replace(target, new JsonStringImpl("qux"));
@@ -465,13 +465,13 @@ public class JsonPointerTest {
 
     @Test(expected = NullPointerException.class)
     public void testReplaceJsonArrayWithTargetNull() {
-        JsonPointer jsonPointer = new JsonPointer("/");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/");
         jsonPointer.replace((JsonArray) null, new JsonStringImpl("qux"));
     }
 
     @Test(expected = JsonException.class)
     public void testReplaceJsonArrayWithEmptyJsonPointer() {
-        JsonPointer jsonPointer = new JsonPointer("");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("");
         JsonArray target = Json.createArrayBuilder().build();
 
         jsonPointer.replace(target, new JsonStringImpl("qux"));
@@ -479,7 +479,7 @@ public class JsonPointerTest {
 
     @Test
     public void testReplaceArrayElement() {
-        JsonPointer jsonPointer = new JsonPointer("/1/1");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/1/1");
         JsonStructure target = Json.createArrayBuilder()
                 .add("bar")
                 .add(Json.createArrayBuilder()
@@ -492,7 +492,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testReplaceArrayElementWithIndexOutOfRange() {
-        JsonPointer jsonPointer = new JsonPointer("/1/2");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/1/2");
         JsonStructure target = Json.createArrayBuilder()
                 .add("bar")
                 .add(Json.createArrayBuilder()
@@ -504,7 +504,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testReplaceArrayElementWithIndexNoNumber() {
-        JsonPointer jsonPointer = new JsonPointer("/1/a");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/1/a");
         JsonStructure target = Json.createArrayBuilder()
                 .add("bar")
                 .add(Json.createArrayBuilder()
@@ -516,7 +516,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testReplaceArrayElementWithLeadingZeroIndex() {
-        JsonPointer jsonPointer = new JsonPointer("/1/01");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/1/01");
         JsonStructure target = Json.createArrayBuilder()
                 .add("bar")
                 .add(Json.createArrayBuilder()
@@ -528,7 +528,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testReplaceArrayElementWithInvalidIndex() {
-        JsonPointer jsonPointer = new JsonPointer("/1/+");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/1/+");
         JsonStructure target = Json.createArrayBuilder()
                 .add("bar")
                 .add(Json.createArrayBuilder()
@@ -540,7 +540,7 @@ public class JsonPointerTest {
 
     @Test
     public void testReplaceObjectMember() {
-        JsonPointer jsonPointer = new JsonPointer("/baz");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/baz");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", "bar")
                 .add("baz", "qux").build(); // {"foo":"bar","baz":"qux"}
@@ -551,7 +551,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testReplaceObjectMemberWithNonexistentTarget1() {
-        JsonPointer jsonPointer = new JsonPointer("/baz/a");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/baz/a");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", "bar")
                 .add("baz", "qux").build(); // {"foo":"bar","baz":"qux"}
@@ -562,7 +562,7 @@ public class JsonPointerTest {
 
     @Test(expected = JsonException.class)
     public void testReplaceObjectMemberWithNonexistentTarget2() {
-        JsonPointer jsonPointer = new JsonPointer("/fo");
+        JsonPointerImpl jsonPointer = new JsonPointerImpl("/fo");
         JsonStructure target = Json.createObjectBuilder()
                 .add("foo", "bar")
                 .add("baz", "qux").build(); // {"foo":"bar","baz":"qux"}
@@ -573,15 +573,15 @@ public class JsonPointerTest {
 
     @Test
     public void testEqualsTrue() {
-        JsonPointer jsonPointer1 = new JsonPointer("/foo/1");
-        JsonPointer jsonPointer2 = new JsonPointer("/foo/1");
+        JsonPointerImpl jsonPointer1 = new JsonPointerImpl("/foo/1");
+        JsonPointerImpl jsonPointer2 = new JsonPointerImpl("/foo/1");
         assertTrue(jsonPointer1.equals(jsonPointer2));
     }
 
     @Test
     public void testEqualsFalse() {
-        JsonPointer jsonPointer1 = new JsonPointer("/foo/1");
-        JsonPointer jsonPointer2 = new JsonPointer("/foo/2");
+        JsonPointerImpl jsonPointer1 = new JsonPointerImpl("/foo/1");
+        JsonPointerImpl jsonPointer2 = new JsonPointerImpl("/foo/2");
         assertFalse(jsonPointer1.equals(jsonPointer2));
     }
 


[5/6] johnzon git commit: fix pom version

Posted by st...@apache.org.
fix pom version


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/bfdab106
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/bfdab106
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/bfdab106

Branch: refs/heads/JSONP-1.1
Commit: bfdab106e4cdc63d131ecacca19559bca6ebae71
Parents: cc830c6
Author: Mark Struberg <st...@apache.org>
Authored: Tue Nov 22 21:37:22 2016 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Tue Nov 22 21:37:22 2016 +0100

----------------------------------------------------------------------
 johnzon-distribution/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/bfdab106/johnzon-distribution/pom.xml
----------------------------------------------------------------------
diff --git a/johnzon-distribution/pom.xml b/johnzon-distribution/pom.xml
index f6f468e..1b0e3cd 100644
--- a/johnzon-distribution/pom.xml
+++ b/johnzon-distribution/pom.xml
@@ -21,7 +21,7 @@
   <parent>
     <artifactId>johnzon</artifactId>
     <groupId>org.apache.johnzon</groupId>
-    <version>0.9.4-SNAPSHOT</version>
+    <version>0.9.6-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>