Interface JsonAccessor<T>

All Known Subinterfaces:
JsonArrayAccessor, JsonObjectAccessor, UnknownTypeJsonAccessor
All Known Implementing Classes:
JsonArrayAccessorImpl, JsonBooleanAccessor, JsonDoubleAccessor, JsonFloatAccessor, JsonIntegerAccessor, JsonLongAccessor, JsonObjectAccessorImpl, JsonStringAccessor

public interface JsonAccessor<T>
An interface that abstracts the ways of accessing values in a JSON tree.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    get(com.google.gson.JsonObject root)
    Get the current value of the element this accessor points to for the given root.
    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.
     
    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 Details

    • get

      Optional<T> get(com.google.gson.JsonObject root)
      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)
      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.
    • getOrCreate

      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.
      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.
    • root

      static JsonObjectAccessor root()