Class JsonPointerImpl

java.lang.Object
org.apache.johnzon.core.JsonPointerImpl
All Implemented Interfaces:
jakarta.json.JsonPointer

public class JsonPointerImpl extends Object implements jakarta.json.JsonPointer
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonPointerImpl(jakarta.json.spi.JsonProvider provider, String jsonPointer)
    Constructs and initializes a JsonPointer.
  • Method Summary

    Modifier and Type
    Method
    Description
    jakarta.json.JsonArray
    add(jakarta.json.JsonArray target, jakarta.json.JsonValue value)
    Adds or replaces a value at the referenced location in the specified target with the specified value.
    jakarta.json.JsonObject
    add(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
    Adds or replaces a value at the referenced location in the specified target with the specified value.
    jakarta.json.JsonStructure
    add(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
    Adds or replaces a value at the referenced location in the specified target with the specified value.
    boolean
    containsValue(jakarta.json.JsonStructure target)
     
    boolean
    Compares this JsonPointer with another object.
    jakarta.json.JsonValue
    getValue(jakarta.json.JsonStructure target)
    Returns the value at the referenced location in the specified target
    int
    Returns the hash code value for this JsonPointer object.
    jakarta.json.JsonArray
    remove(jakarta.json.JsonArray target)
    Removes the value at the reference location in the specified target
    jakarta.json.JsonObject
    remove(jakarta.json.JsonObject target)
    Removes the value at the reference location in the specified target
    jakarta.json.JsonStructure
    remove(jakarta.json.JsonStructure target)
    Removes the value at the reference location in the specified target
    jakarta.json.JsonArray
    replace(jakarta.json.JsonArray target, jakarta.json.JsonValue value)
    Replaces the value at the referenced location in the specified
    jakarta.json.JsonObject
    replace(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
    Replaces the value at the referenced location in the specified
    jakarta.json.JsonStructure
    replace(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
    Replaces the value at the referenced location in the specified target with the specified value.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JsonPointerImpl

      public JsonPointerImpl(jakarta.json.spi.JsonProvider provider, String jsonPointer)
      Constructs and initializes a JsonPointer.
      Parameters:
      provider - the JSON provider used to create this pointer
      jsonPointer - the JSON Pointer string
      Throws:
      NullPointerException - if jsonPointer is null
      jakarta.json.JsonException - if jsonPointer is not a valid JSON Pointer
  • Method Details

    • equals

      public boolean equals(Object obj)
      Compares this JsonPointer with another object.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare this JsonPointer against
      Returns:
      true if the given object is a JsonPointer with the same reference tokens as this one, false otherwise.
    • hashCode

      public int hashCode()
      Returns the hash code value for this JsonPointer object. The hash code of this object is defined by the hash codes of it's reference tokens.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this JsonPointer object
    • getValue

      public jakarta.json.JsonValue getValue(jakarta.json.JsonStructure target)
      Returns the value at the referenced location in the specified target
      Specified by:
      getValue in interface jakarta.json.JsonPointer
      Parameters:
      target - the target referenced by this JsonPointer
      Returns:
      the referenced value in the target.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the referenced value does not exist
    • containsValue

      public boolean containsValue(jakarta.json.JsonStructure target)
      Specified by:
      containsValue in interface jakarta.json.JsonPointer
    • add

      public jakarta.json.JsonStructure add(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
      Adds or replaces a value at the referenced location in the specified target with the specified value.
      1. If the reference is the target (empty JSON Pointer string), the specified value, which must be the same type as specified target, is returned.
      2. If the reference is an array element, the specified 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.
      3. If the reference is a name/value pair of a JsonObject, and the referenced value exists, the value is replaced by the specified value. If the value does not exist, a new name/value pair is added to the object.
      Specified by:
      add in interface jakarta.json.JsonPointer
      Parameters:
      target - the target referenced by this JsonPointer
      value - the value to be added
      Returns:
      the transformed target after the value is added.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the reference is an array element and the index is out of range (index < 0 || index > array size), or if the pointer contains references to non-existing objects or arrays.
    • add

      public jakarta.json.JsonObject add(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
      Adds or replaces a value at the referenced location in the specified target with the specified value.
      Parameters:
      target - the target referenced by this JsonPointer
      value - the value to be added
      Returns:
      the transformed target after the value is added.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the reference is an array element and the index is out of range (index < 0 || index > array size), or if the pointer contains references to non-existing objects or arrays.
      See Also:
    • add

      public jakarta.json.JsonArray add(jakarta.json.JsonArray target, jakarta.json.JsonValue value)
      Adds or replaces a value at the referenced location in the specified target with the specified value.
      Parameters:
      target - the target referenced by this JsonPointer
      value - the value to be added
      Returns:
      the transformed target after the value is added.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the reference is an array element and the index is out of range (index < 0 || index > array size), or if the pointer contains references to non-existing objects or arrays.
      See Also:
    • replace

      public jakarta.json.JsonStructure replace(jakarta.json.JsonStructure target, jakarta.json.JsonValue value)
      Replaces the value at the referenced location in the specified target with the specified value.
      Specified by:
      replace in interface jakarta.json.JsonPointer
      Parameters:
      target - the target referenced by this JsonPointer
      value - the value to be stored at the referenced location
      Returns:
      the transformed target after the value is replaced.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the referenced value does not exist, or if the reference is the target.
    • replace

      public jakarta.json.JsonObject replace(jakarta.json.JsonObject target, jakarta.json.JsonValue value)
      Replaces the value at the referenced location in the specified
      Parameters:
      target - the target referenced by this JsonPointer
      value - the value to be stored at the referenced location
      Returns:
      the transformed target after the value is replaced.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the referenced value does not exist, or if the reference is the target.
      See Also:
    • replace

      public jakarta.json.JsonArray replace(jakarta.json.JsonArray target, jakarta.json.JsonValue value)
      Replaces the value at the referenced location in the specified
      Parameters:
      target - the target referenced by this JsonPointer
      value - the value to be stored at the referenced location
      Returns:
      the transformed target after the value is replaced.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the referenced value does not exist, or if the reference is the target.
      See Also:
    • remove

      public jakarta.json.JsonStructure remove(jakarta.json.JsonStructure target)
      Removes the value at the reference location in the specified target
      Specified by:
      remove in interface jakarta.json.JsonPointer
      Parameters:
      target - the target referenced by this JsonPointer
      Returns:
      the transformed target after the value is removed.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the referenced value does not exist, or if the reference is the target.
    • remove

      public jakarta.json.JsonObject remove(jakarta.json.JsonObject target)
      Removes the value at the reference location in the specified target
      Parameters:
      target - the target referenced by this JsonPointer
      Returns:
      the transformed target after the value is removed.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the referenced value does not exist, or if the reference is the target.
      See Also:
    • remove

      public jakarta.json.JsonArray remove(jakarta.json.JsonArray target)
      Removes the value at the reference location in the specified target
      Parameters:
      target - the target referenced by this JsonPointer
      Returns:
      the transformed target after the value is removed.
      Throws:
      NullPointerException - if target is null
      jakarta.json.JsonException - if the referenced value does not exist, or if the reference is the target.
      See Also:
    • toString

      public String toString()
      Specified by:
      toString in interface jakarta.json.JsonPointer
      Overrides:
      toString in class Object