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:
root(),JsonObjectAccessor,JsonArrayAccessor,UnknownTypeJsonAccessor
-
-
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 givenroot.TgetOrCreate(com.google.gson.JsonObject root, Supplier<? extends T> newValueSupplier)Get the current value of the element this accessor points to for the givenroot, creating it and setting it if it hasn't been set yet.static JsonObjectAccessorroot()voidset(com.google.gson.JsonObject root, T newValue)Set the given value on the element this accessor points to for the givenroot.
-
-
-
Method Detail
-
get
Optional<T> get(com.google.gson.JsonObject root)
Get the current value of the element this accessor points to for the givenroot.- Parameters:
root- The root to be accessed.- Returns:
- An
Optionalcontaining the current value pointed to by this accessor on theroot, orOptional.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 givenroot.- 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 givenroot, 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()
-
-