Class JsonMergePatch

java.lang.Object
org.eclipse.ditto.json.JsonMergePatch

@Immutable public final class JsonMergePatch extends Object
This class is responsible to compute or apply a JSON merge patch according to RFC 7386 for json values.
Since:
2.4.0
  • Method Details

    • compute

      public static Optional<JsonMergePatch> compute(JsonValue oldValue, JsonValue newValue)
      This method computes the change from the given oldValue to the given newValue. The result is a JSON merge patch according to RFC 7386.
      Parameters:
      oldValue - the original value
      newValue - the new changed value
      Returns:
      a JSON merge patch according to RFC 7386 or empty if values are equal.
    • of

      public static JsonMergePatch of(JsonPointer path, JsonValue mergePatch)
      Creates a JsonMergePatch with an patch object containing the given mergePatch at the given path.
      Parameters:
      path - The path on which the given mergePatch should be applied later.
      mergePatch - the actual patch.
      Returns:
      the merge patch.
    • of

      public static JsonMergePatch of(JsonValue mergePatch)
      Creates a JsonMergePatch with an patch object containing the given mergePatch at root level.
      Parameters:
      mergePatch - the actual patch.
      Returns:
      the merge patch.
    • applyOn

      public JsonValue applyOn(JsonValue jsonValue)
      Applies this merge patch on the given json value.
      Parameters:
      jsonValue - the json value that should be patched.
      Returns:
      the patched json value.
    • asJsonValue

      public JsonValue asJsonValue()
      Returns:
      the merge patch json value
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object