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.
-
Method Summary
Modifier and TypeMethodDescriptionget(com.google.gson.JsonObject root) Get the current value of the element this accessor points to for the givenroot.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.static JsonObjectAccessorroot()voidSet the given value on the element this accessor points to for the givenroot.
-
Method Details
-
get
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
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
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
-