public interface JsonAccessor<T>
root()
,
JsonObjectAccessor
,
JsonArrayAccessor
,
UnknownTypeJsonAccessor
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 . |
Optional<T> get(com.google.gson.JsonObject root) throws UnexpectedJsonElementTypeException
root
.root
- The root to be accessed.Optional
containing the current value pointed to by this accessor on the root
,
or Optional.empty()
if it doesn't exist.UnexpectedJsonElementTypeException
- If an element in the path has unexpected type,
preventing access to the element this accessor points to.void set(com.google.gson.JsonObject root, T newValue) throws UnexpectedJsonElementTypeException
root
.root
- The root to be accessed.newValue
- The value to set.UnexpectedJsonElementTypeException
- If an element in the path has unexpected type, preventing
access to the element this accessor points to.void add(com.google.gson.JsonObject root, T newValue) throws UnexpectedJsonElementTypeException
root
.
This method differs from set(JsonObject, Object)
:
set
.
JsonNull
, the current value
is replaced by an array containing the current value followed by the given value.
UnexpectedJsonElementTypeException
is thrown.
root
- The root to be accessed.newValue
- The value to add.UnexpectedJsonElementTypeException
- If an element in the path has unexpected type, preventing
write access to the element this accessor points to.T getOrCreate(com.google.gson.JsonObject root, Supplier<? extends T> newValueSupplier) throws UnexpectedJsonElementTypeException
root
,
creating it and setting it if it hasn't been set yet.root
- The root to be accessed.newValueSupplier
- The value to set and return if the current value hasn't been set yet.root
, always non-null.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.String getStaticAbsolutePath()
null
for the root accessor.static JsonObjectAccessor root()
Copyright © 2006-2017 Red Hat, Inc. All Rights Reserved