org.hibernate.search.elasticsearch.gson.impl

## Interface JsonAccessor<T>

- All Known Subinterfaces:
    JsonArrayAccessor, JsonObjectAccessor, UnknownTypeJsonAccessor
  All Known Implementing Classes:
    JsonArrayAccessorImpl, JsonBooleanAccessorImpl, JsonDoubleAccessorImpl, JsonFloatAccessorImpl, JsonIntegerAccessorImpl, JsonLongAccessorImpl, JsonObjectAccessorImpl, JsonStringAccessorImpl

      public interface JsonAccessor<T>

  An interface that abstracts the ways of accessing values in a JSON tree.
  Author:
    Yoann Rodiere
  See Also:
    `root()`, `JsonObjectAccessor`, `JsonArrayAccessor`, `UnknownTypeJsonAccessor`

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(com.google.gson.JsonObject root, T newValue)` Add the given primitive value to the element this accessor points to for the given `root`.
    `Optional<T>` | `get(com.google.gson.JsonObject root)` Get the current value of the element this accessor points to for the given `root`.
    `T` | `getOrCreate(com.google.gson.JsonObject root, Supplier<? extends T> newValueSupplier)` Get the current value of the element this accessor points to for the given `root`, creating it and setting it if it hasn't been set yet.
    `String` | `getStaticAbsolutePath()`
    `static JsonObjectAccessor` | `root()`
    `void` | `set(com.google.gson.JsonObject root, T newValue)` Set the given value on the element this accessor points to for the given `root`.

- - ### Method Detail

    - #### get

          Optional<T> get(com.google.gson.JsonObject root)
                   throws UnexpectedJsonElementTypeException

      Get the current value of the element this accessor points to for the given `root`.
      Parameters:
        `root` - The root to be accessed.
      Returns:
        An `Optional` containing the current value pointed to by this accessor on the `root`, or `Optional.empty()` if it doesn't exist.
      Throws:
        `UnexpectedJsonElementTypeException` - If an element in the path has unexpected type, preventing access to the element this accessor points to.

    - #### set

          void set(com.google.gson.JsonObject root,
                   T newValue)
            throws UnexpectedJsonElementTypeException

      Set the given value on the element this accessor points to for the given `root`.
      Parameters:
        `root` - The root to be accessed.
        `newValue` - The value to set.
      Throws:
        `UnexpectedJsonElementTypeException` - If an element in the path has unexpected type, preventing access to the element this accessor points to.

    - #### add

          void add(com.google.gson.JsonObject root,
                   T newValue)
            throws UnexpectedJsonElementTypeException

      Add the given primitive value to the element this accessor points to for the given `root`.

      This method differs from `set(JsonObject, Object)`:

      - If there is currently no value, the given value is simply `set`.
      - If the current value is an array, the given value is added to this array.
      - If the current value is a primitive or `JsonNull`, the current value is replaced by an array containing the current value followed by the given value.
      - Otherwise (i.e. if the current value is an object), an `UnexpectedJsonElementTypeException` is thrown.
      Parameters:
        `root` - The root to be accessed.
        `newValue` - The value to add.
      Throws:
        `UnexpectedJsonElementTypeException` - If an element in the path has unexpected type, preventing write access to the element this accessor points to.

    - #### getOrCreate

          T getOrCreate(com.google.gson.JsonObject root,
                        Supplier<? extends T> newValueSupplier)
                 throws UnexpectedJsonElementTypeException

      Get the current value of the element this accessor points to for the given `root`, creating it and setting it if it hasn't been set yet.
      Parameters:
        `root` - The root to be accessed.
        `newValueSupplier` - The value to set and return if the current value hasn't been set yet.
      Returns:
        The current value pointed to by this accessor on the `root`, always non-null.
      Throws:
        `UnexpectedJsonElementTypeException` - if the element already exists and is not of the expected type, or if an element in the path has unexpected type, preventing access to the element this accessor points to.

    - #### getStaticAbsolutePath

          String getStaticAbsolutePath()

      Returns:
        The absolute path representing this accessor, excluding runtime details such as array indices or types. `null` for the root accessor.

    - #### root

          static JsonObjectAccessor root()

Copyright © 2006-2017 Red Hat, Inc. All Rights Reserved