Interface JSONDelta.ChangeMap

All Superinterfaces:
Map<String,JSON>
Enclosing interface:
JSONDelta

public static interface JSONDelta.ChangeMap extends Map<String,JSON>
An unmodifiable map describing the changes to a JSON value.

The JSONDelta.inserted() method returns a ChangeMap describing the parts of the second JSON value not found in the first JSON value. Similarly, JSONDelta.removed() returns a ChangeMap describing the parts of the first JSON value not found in the second JSON value.

The map contains an entry for each change, as follows:

  • The key is a JSON Pointer syntax reference locating the change in the complete value. Since a JSON value is a list of zero or more data items, the reference always begins with an array index. For example, the first part is identified by the JSON Pointer /0.
  • The value is part of the complete value. It is returned as a JSON that can be parsed independently as a unit, or converted to JSON.

Instances cannot be modified. Destructive methods such as Map.put(Object, Object) throw UnsupportedOperationException if called.

An IllegalArgumentException will be thrown if an invalid JSON pointer expression is passed to Map.get(Object), Map.containsKey(Object), descendants(String), or intersection(String). This only occurs if the expression does not start with / and is not empty.

  • Method Details

    • descendants

      JSONDelta.ChangeMap descendants(String pointer)
      Returns a view of the portion of this map whose keys are descendants of pointer. If pointer is contained in this map, it will be included in the result.
      Throws:
      IllegalArgumentException - if pointer is an invalid JSON Pointer expression
    • intersection

      JSONDelta.ChangeMap intersection(String pointer)
      Returns a view of the portion of this map whose keys are descendants or parents of pointer. If pointer is contained in this map, it will be included in the result.

      This method can be used to determine whether a structural delta affects a particular part of a JSON value. For example:

       if (!structuralDelta.removed().intersection("/contact/address").isEmpty()) {
         // The structural delta removes elements that affect '/contact/address'.
       }
       if (!structuralDelta.inserted().intersection("/contact/address").isEmpty()) {
         // The structural delta inserts elements that affect '/contact/address'.
       }
       
      Throws:
      IllegalArgumentException - if pointer is an invalid JSON Pointer expression