Interface JsonAccessor<T>

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      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.
      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)
        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.