Class JsonPatchBuilderImpl

  • All Implemented Interfaces:
    jakarta.json.JsonPatchBuilder

    public final class JsonPatchBuilderImpl
    extends java.lang.Object
    implements jakarta.json.JsonPatchBuilder
    A builder for constructing a JSON Patch by adding JSON Patch operations incrementally.

    The following illustrates the approach.

       JsonPatchBuilder builder = Json.createPatchBuilder();
       JsonPatch patch = builder.add("/John/phones/office", "1234-567")
                                .remove("/Amy/age")
                                .build();
     
    The result is equivalent to the following JSON Patch.
     [
        {"op" = "add", "path" = "/John/phones/office", "value" = "1234-567"},
        {"op" = "remove", "path" = "/Amy/age"}
     ] 
    Since:
    1.1
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      jakarta.json.JsonPatchBuilder add​(java.lang.String path, boolean value)
      Adds an "add" JSON Patch operation
      jakarta.json.JsonPatchBuilder add​(java.lang.String path, int value)
      Adds an "add" JSON Patch operation
      jakarta.json.JsonPatchBuilder add​(java.lang.String path, jakarta.json.JsonValue value)
      Adds an "add" JSON Patch operation.
      jakarta.json.JsonPatchBuilder add​(java.lang.String path, java.lang.String value)
      Adds an "add" JSON Patch operation
      <T extends jakarta.json.JsonStructure>
      T
      apply​(T target)
      A convenience method for new JsonPatchImpl(build()).apply(target).
      jakarta.json.JsonPatch build()
      Returns the patch operation in a JsonPatch
      jakarta.json.JsonArray buildAsJsonArray()
      Returns the patch operations in a JsonArray
      jakarta.json.JsonPatchBuilder copy​(java.lang.String path, java.lang.String from)
      Adds a "copy" JSON Patch operation.
      jakarta.json.JsonPatchBuilder move​(java.lang.String path, java.lang.String from)
      Adds a "move" JSON Patch operation.
      jakarta.json.JsonPatchBuilder remove​(java.lang.String path)
      Adds a "remove" JSON Patch operation.
      jakarta.json.JsonPatchBuilder replace​(java.lang.String path, boolean value)
      Adds a "replace" JSON Patch operation.
      jakarta.json.JsonPatchBuilder replace​(java.lang.String path, int value)
      Adds a "replace" JSON Patch operation.
      jakarta.json.JsonPatchBuilder replace​(java.lang.String path, jakarta.json.JsonValue value)
      Adds a "replace" JSON Patch operation.
      jakarta.json.JsonPatchBuilder replace​(java.lang.String path, java.lang.String value)
      Adds a "replace" JSON Patch operation.
      jakarta.json.JsonPatchBuilder test​(java.lang.String path, boolean value)
      Adds a "test" JSON Patch operation.
      jakarta.json.JsonPatchBuilder test​(java.lang.String path, int value)
      Adds a "test" JSON Patch operation.
      jakarta.json.JsonPatchBuilder test​(java.lang.String path, jakarta.json.JsonValue value)
      Adds a "test" JSON Patch operation.
      jakarta.json.JsonPatchBuilder test​(java.lang.String path, java.lang.String value)
      Adds a "test" JSON Patch operation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • builder

        private final jakarta.json.JsonArrayBuilder builder
    • Constructor Detail

      • JsonPatchBuilderImpl

        public JsonPatchBuilderImpl​(jakarta.json.JsonArray patch,
                                    JsonContext jsonContext)
        Creates a JsonPatchBuilderImpl, starting with the specified JSON Patch
        Parameters:
        patch - the JSON Patch
      • JsonPatchBuilderImpl

        public JsonPatchBuilderImpl​(JsonContext jsonContext)
        Creates JsonPatchBuilderImpl with empty JSON Patch
    • Method Detail

      • apply

        public <T extends jakarta.json.JsonStructure> T apply​(T target)
        A convenience method for new JsonPatchImpl(build()).apply(target). The target is not modified by the patch.
        Type Parameters:
        T - the target type, must be a subtype of JsonStructure
        Parameters:
        target - the target to apply the patch operations
        Returns:
        the transformed target after the patch
        Throws:
        jakarta.json.JsonException - if the supplied JSON Patch is malformed or if it contains references to non-existing members
      • add

        public jakarta.json.JsonPatchBuilder add​(java.lang.String path,
                                                 jakarta.json.JsonValue value)
        Adds an "add" JSON Patch operation.
        Specified by:
        add in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • add

        public jakarta.json.JsonPatchBuilder add​(java.lang.String path,
                                                 java.lang.String value)
        Adds an "add" JSON Patch operation
        Specified by:
        add in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • add

        public jakarta.json.JsonPatchBuilder add​(java.lang.String path,
                                                 int value)
        Adds an "add" JSON Patch operation
        Specified by:
        add in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • add

        public jakarta.json.JsonPatchBuilder add​(java.lang.String path,
                                                 boolean value)
        Adds an "add" JSON Patch operation
        Specified by:
        add in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • remove

        public jakarta.json.JsonPatchBuilder remove​(java.lang.String path)
        Adds a "remove" JSON Patch operation.
        Specified by:
        remove in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        Returns:
        this JsonPatchBuilder
      • replace

        public jakarta.json.JsonPatchBuilder replace​(java.lang.String path,
                                                     jakarta.json.JsonValue value)
        Adds a "replace" JSON Patch operation.
        Specified by:
        replace in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • replace

        public jakarta.json.JsonPatchBuilder replace​(java.lang.String path,
                                                     java.lang.String value)
        Adds a "replace" JSON Patch operation.
        Specified by:
        replace in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • replace

        public jakarta.json.JsonPatchBuilder replace​(java.lang.String path,
                                                     int value)
        Adds a "replace" JSON Patch operation.
        Specified by:
        replace in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • replace

        public jakarta.json.JsonPatchBuilder replace​(java.lang.String path,
                                                     boolean value)
        Adds a "replace" JSON Patch operation.
        Specified by:
        replace in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • move

        public jakarta.json.JsonPatchBuilder move​(java.lang.String path,
                                                  java.lang.String from)
        Adds a "move" JSON Patch operation.
        Specified by:
        move in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        from - the "from" member of the operation
        Returns:
        this JsonPatchBuilder
      • copy

        public jakarta.json.JsonPatchBuilder copy​(java.lang.String path,
                                                  java.lang.String from)
        Adds a "copy" JSON Patch operation.
        Specified by:
        copy in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        from - the "from" member of the operation
        Returns:
        this JsonPatchBuilder
      • test

        public jakarta.json.JsonPatchBuilder test​(java.lang.String path,
                                                  jakarta.json.JsonValue value)
        Adds a "test" JSON Patch operation.
        Specified by:
        test in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • test

        public jakarta.json.JsonPatchBuilder test​(java.lang.String path,
                                                  java.lang.String value)
        Adds a "test" JSON Patch operation.
        Specified by:
        test in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • test

        public jakarta.json.JsonPatchBuilder test​(java.lang.String path,
                                                  int value)
        Adds a "test" JSON Patch operation.
        Specified by:
        test in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • test

        public jakarta.json.JsonPatchBuilder test​(java.lang.String path,
                                                  boolean value)
        Adds a "test" JSON Patch operation.
        Specified by:
        test in interface jakarta.json.JsonPatchBuilder
        Parameters:
        path - the "path" member of the operation
        value - the "value" member of the operation
        Returns:
        this JsonPatchBuilder
      • buildAsJsonArray

        public jakarta.json.JsonArray buildAsJsonArray()
        Returns the patch operations in a JsonArray
        Returns:
        the patch operations in a JsonArray
      • build

        public jakarta.json.JsonPatch build()
        Returns the patch operation in a JsonPatch
        Specified by:
        build in interface jakarta.json.JsonPatchBuilder
        Returns:
        the patch operation in a JsonPatch