public class JsonContext extends java.lang.Object implements DocumentContext
| Modifier and Type | Method and Description |
|---|---|
DocumentContext |
add(JsonPath path,
java.lang.Object value)
Add value to array at the given path
|
DocumentContext |
add(java.lang.String path,
java.lang.Object value,
Predicate... filters)
Add value to array
|
Configuration |
configuration()
Returns the configuration used for reading
|
DocumentContext |
delete(JsonPath path)
Deletes the given path
|
DocumentContext |
delete(java.lang.String path,
Predicate... filters)
Deletes the given path
|
java.lang.Object |
json()
Returns the JSON model that this context is operating on
|
java.lang.String |
jsonString()
Returns the JSON model that this context is operating on as a JSON string
|
ReadContext |
limit(int maxResults)
Stops evaluation when maxResults limit has been reached
|
DocumentContext |
map(JsonPath path,
MapFunction mapFunction)
Replaces the value on the given path with the result of the
MapFunction. |
DocumentContext |
map(java.lang.String path,
MapFunction mapFunction,
Predicate... filters)
Replaces the value on the given path with the result of the
MapFunction. |
DocumentContext |
put(JsonPath path,
java.lang.String key,
java.lang.Object value)
Add or update the key with a the given value at the given path
|
DocumentContext |
put(java.lang.String path,
java.lang.String key,
java.lang.Object value,
Predicate... filters)
Add or update the key with a the given value at the given path
|
<T> T |
read(JsonPath path)
Reads the given path from this context
|
<T> T |
read(JsonPath path,
java.lang.Class<T> type)
Reads the given path from this context
|
<T> T |
read(JsonPath path,
TypeRef<T> type)
Reads the given path from this context
Sample code to create a TypeRef
TypeRef ref = new TypeRef |
<T> T |
read(java.lang.String path,
java.lang.Class<T> type,
Predicate... filters)
Reads the given path from this context
|
<T> T |
read(java.lang.String path,
Predicate... filters)
Reads the given path from this context
|
<T> T |
read(java.lang.String path,
TypeRef<T> type)
Reads the given path from this context
Sample code to create a TypeRef
TypeRef ref = new TypeRef |
DocumentContext |
renameKey(JsonPath path,
java.lang.String oldKeyName,
java.lang.String newKeyName)
Renames the last key element of a given path.
|
DocumentContext |
renameKey(java.lang.String path,
java.lang.String oldKeyName,
java.lang.String newKeyName,
Predicate... filters)
Renames the last key element of a given path.
|
DocumentContext |
set(JsonPath path,
java.lang.Object newValue)
Set the value a the given path
|
DocumentContext |
set(java.lang.String path,
java.lang.Object newValue,
Predicate... filters)
Set the value a the given path
|
ReadContext |
withListeners(EvaluationListener... listener)
Adds listener to the evaluation of this path
|
public Configuration configuration()
ReadContextconfiguration in interface ReadContextconfiguration in interface WriteContextpublic java.lang.Object json()
ReadContextjson in interface ReadContextjson in interface WriteContextpublic java.lang.String jsonString()
ReadContextjsonString in interface ReadContextjsonString in interface WriteContextpublic <T> T read(java.lang.String path,
Predicate... filters)
ReadContextread in interface ReadContextpath - path to readfilters - filterspublic <T> T read(java.lang.String path,
java.lang.Class<T> type,
Predicate... filters)
ReadContextread in interface ReadContextpath - path to readtype - expected return type (will try to map)filters - filterspublic <T> T read(JsonPath path)
ReadContextread in interface ReadContextpath - path to applypublic <T> T read(JsonPath path, java.lang.Class<T> type)
ReadContextread in interface ReadContextpath - path to applytype - expected return type (will try to map)public <T> T read(JsonPath path, TypeRef<T> type)
ReadContext
TypeRef ref = new TypeRef>() {};
read in interface ReadContextpath - path to applytype - expected return type (will try to map)public <T> T read(java.lang.String path,
TypeRef<T> type)
ReadContext
TypeRef ref = new TypeRef>() {};
read in interface ReadContextpath - path to applytype - expected return type (will try to map)public ReadContext limit(int maxResults)
ReadContextlimit in interface ReadContextpublic ReadContext withListeners(EvaluationListener... listener)
ReadContextwithListeners in interface ReadContextlistener - listeners to addpublic DocumentContext set(java.lang.String path, java.lang.Object newValue, Predicate... filters)
WriteContextset in interface WriteContextpath - path to setnewValue - new valuefilters - filterspublic DocumentContext set(JsonPath path, java.lang.Object newValue)
WriteContextset in interface WriteContextpath - path to setnewValue - new valuepublic DocumentContext map(java.lang.String path, MapFunction mapFunction, Predicate... filters)
WriteContextMapFunction.map in interface WriteContextpath - path to be converted setmapFunction - Converter object to be invokedfilters - filterspublic DocumentContext map(JsonPath path, MapFunction mapFunction)
WriteContextMapFunction.map in interface WriteContextpath - path to be converted setmapFunction - Converter object to be invoked (or lambda:))public DocumentContext delete(java.lang.String path, Predicate... filters)
WriteContextdelete in interface WriteContextpath - path to deletefilters - filterspublic DocumentContext delete(JsonPath path)
WriteContextdelete in interface WriteContextpath - path to deletepublic DocumentContext add(java.lang.String path, java.lang.Object value, Predicate... filters)
WriteContext
List array = new ArrayList(){{
add(0);
add(1);
}};
JsonPath.parse(array).add("$", 2);
assertThat(array).containsExactly(0,1,2);
add in interface WriteContextpath - path to arrayvalue - value to addfilters - filterspublic DocumentContext add(JsonPath path, java.lang.Object value)
WriteContextadd in interface WriteContextpath - path to arrayvalue - value to addpublic DocumentContext put(java.lang.String path, java.lang.String key, java.lang.Object value, Predicate... filters)
WriteContextput in interface WriteContextpath - path to objectkey - key to addvalue - value of keyfilters - filterspublic DocumentContext renameKey(java.lang.String path, java.lang.String oldKeyName, java.lang.String newKeyName, Predicate... filters)
WriteContextrenameKey in interface WriteContextpath - The path to the old key. Should be resolved to a map
or an array including map items.oldKeyName - The old key name.newKeyName - The new key name.filters - filters.public DocumentContext renameKey(JsonPath path, java.lang.String oldKeyName, java.lang.String newKeyName)
WriteContextrenameKey in interface WriteContextpath - The path to the old key. Should be resolved to a map
or an array including map items.oldKeyName - The old key name.newKeyName - The new key name.public DocumentContext put(JsonPath path, java.lang.String key, java.lang.Object value)
WriteContextput in interface WriteContextpath - path to arraykey - key to addvalue - value of key