Package com.jayway.jsonpath.internal
Class JsonContext
- java.lang.Object
-
- com.jayway.jsonpath.internal.JsonContext
-
- All Implemented Interfaces:
DocumentContext,ReadContext,WriteContext
public class JsonContext extends java.lang.Object implements DocumentContext
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DocumentContextadd(JsonPath path, java.lang.Object value)Add value to array at the given pathDocumentContextadd(java.lang.String path, java.lang.Object value, Predicate... filters)Add value to arrayConfigurationconfiguration()Returns the configuration used for readingDocumentContextdelete(JsonPath path)Deletes the given pathDocumentContextdelete(java.lang.String path, Predicate... filters)Deletes the given pathjava.lang.Objectjson()Returns the JSON model that this context is operating onjava.lang.StringjsonString()Returns the JSON model that this context is operating on as a JSON stringReadContextlimit(int maxResults)Stops evaluation when maxResults limit has been reachedDocumentContextmap(JsonPath path, MapFunction mapFunction)Replaces the value on the given path with the result of theMapFunction.DocumentContextmap(java.lang.String path, MapFunction mapFunction, Predicate... filters)Replaces the value on the given path with the result of theMapFunction.DocumentContextput(JsonPath path, java.lang.String key, java.lang.Object value)Add or update the key with a the given value at the given pathDocumentContextput(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> Tread(JsonPath path)Reads the given path from this context<T> Tread(JsonPath path, TypeRef<T> type)Reads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRef- >() {};
<T> Tread(JsonPath path, java.lang.Class<T> type)Reads the given path from this context<T> Tread(java.lang.String path, Predicate... filters)Reads the given path from this context<T> Tread(java.lang.String path, TypeRef<T> type)Reads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRef- >() {};
<T> Tread(java.lang.String path, java.lang.Class<T> type, Predicate... filters)Reads the given path from this contextDocumentContextrenameKey(JsonPath path, java.lang.String oldKeyName, java.lang.String newKeyName)Renames the last key element of a given path.DocumentContextrenameKey(java.lang.String path, java.lang.String oldKeyName, java.lang.String newKeyName, Predicate... filters)Renames the last key element of a given path.DocumentContextset(JsonPath path, java.lang.Object newValue)Set the value a the given pathDocumentContextset(java.lang.String path, java.lang.Object newValue, Predicate... filters)Set the value a the given pathReadContextwithListeners(EvaluationListener... listener)Adds listener to the evaluation of this path
-
-
-
Method Detail
-
configuration
public Configuration configuration()
Description copied from interface:ReadContextReturns the configuration used for reading- Specified by:
configurationin interfaceReadContext- Specified by:
configurationin interfaceWriteContext- Returns:
- an immutable configuration
-
json
public java.lang.Object json()
Description copied from interface:ReadContextReturns the JSON model that this context is operating on- Specified by:
jsonin interfaceReadContext- Specified by:
jsonin interfaceWriteContext- Returns:
- json model
-
jsonString
public java.lang.String jsonString()
Description copied from interface:ReadContextReturns the JSON model that this context is operating on as a JSON string- Specified by:
jsonStringin interfaceReadContext- Specified by:
jsonStringin interfaceWriteContext- Returns:
- json model as string
-
read
public <T> T read(java.lang.String path, Predicate... filters)Description copied from interface:ReadContextReads the given path from this context- Specified by:
readin interfaceReadContext- Parameters:
path- path to readfilters- filters- Returns:
- result
-
read
public <T> T read(java.lang.String path, java.lang.Class<T> type, Predicate... filters)Description copied from interface:ReadContextReads the given path from this context- Specified by:
readin interfaceReadContext- Parameters:
path- path to readtype- expected return type (will try to map)filters- filters- Returns:
- result
-
read
public <T> T read(JsonPath path)
Description copied from interface:ReadContextReads the given path from this context- Specified by:
readin interfaceReadContext- Parameters:
path- path to apply- Returns:
- result
-
read
public <T> T read(JsonPath path, java.lang.Class<T> type)
Description copied from interface:ReadContextReads the given path from this context- Specified by:
readin interfaceReadContext- Parameters:
path- path to applytype- expected return type (will try to map)- Returns:
- result
-
read
public <T> T read(JsonPath path, TypeRef<T> type)
Description copied from interface:ReadContextReads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRef- >() {};
- Specified by:
readin interfaceReadContext- Parameters:
path- path to applytype- expected return type (will try to map)- Returns:
- result
-
read
public <T> T read(java.lang.String path, TypeRef<T> type)Description copied from interface:ReadContextReads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRef- >() {};
- Specified by:
readin interfaceReadContext- Parameters:
path- path to applytype- expected return type (will try to map)- Returns:
- result
-
limit
public ReadContext limit(int maxResults)
Description copied from interface:ReadContextStops evaluation when maxResults limit has been reached- Specified by:
limitin interfaceReadContext- Returns:
- the read context
-
withListeners
public ReadContext withListeners(EvaluationListener... listener)
Description copied from interface:ReadContextAdds listener to the evaluation of this path- Specified by:
withListenersin interfaceReadContext- Parameters:
listener- listeners to add- Returns:
- the read context
-
set
public DocumentContext set(java.lang.String path, java.lang.Object newValue, Predicate... filters)
Description copied from interface:WriteContextSet the value a the given path- Specified by:
setin interfaceWriteContext- Parameters:
path- path to setnewValue- new valuefilters- filters- Returns:
- a document context
-
set
public DocumentContext set(JsonPath path, java.lang.Object newValue)
Description copied from interface:WriteContextSet the value a the given path- Specified by:
setin interfaceWriteContext- Parameters:
path- path to setnewValue- new value- Returns:
- a document context
-
map
public DocumentContext map(java.lang.String path, MapFunction mapFunction, Predicate... filters)
Description copied from interface:WriteContextReplaces the value on the given path with the result of theMapFunction.- Specified by:
mapin interfaceWriteContext- Parameters:
path- path to be converted setmapFunction- Converter object to be invokedfilters- filters- Returns:
- a document context
-
map
public DocumentContext map(JsonPath path, MapFunction mapFunction)
Description copied from interface:WriteContextReplaces the value on the given path with the result of theMapFunction.- Specified by:
mapin interfaceWriteContext- Parameters:
path- path to be converted setmapFunction- Converter object to be invoked (or lambda:))- Returns:
- a document context
-
delete
public DocumentContext delete(java.lang.String path, Predicate... filters)
Description copied from interface:WriteContextDeletes the given path- Specified by:
deletein interfaceWriteContext- Parameters:
path- path to deletefilters- filters- Returns:
- a document context
-
delete
public DocumentContext delete(JsonPath path)
Description copied from interface:WriteContextDeletes the given path- Specified by:
deletein interfaceWriteContext- Parameters:
path- path to delete- Returns:
- a document context
-
add
public DocumentContext add(java.lang.String path, java.lang.Object value, Predicate... filters)
Description copied from interface:WriteContextAdd value to arrayListarray = new ArrayList (){{ add(0); add(1); }}; JsonPath.parse(array).add("$", 2); assertThat(array).containsExactly(0,1,2); - Specified by:
addin interfaceWriteContext- Parameters:
path- path to arrayvalue- value to addfilters- filters- Returns:
- a document context
-
add
public DocumentContext add(JsonPath path, java.lang.Object value)
Description copied from interface:WriteContextAdd value to array at the given path- Specified by:
addin interfaceWriteContext- Parameters:
path- path to arrayvalue- value to add- Returns:
- a document context
-
put
public DocumentContext put(java.lang.String path, java.lang.String key, java.lang.Object value, Predicate... filters)
Description copied from interface:WriteContextAdd or update the key with a the given value at the given path- Specified by:
putin interfaceWriteContext- Parameters:
path- path to objectkey- key to addvalue- value of keyfilters- filters- Returns:
- a document context
-
renameKey
public DocumentContext renameKey(java.lang.String path, java.lang.String oldKeyName, java.lang.String newKeyName, Predicate... filters)
Description copied from interface:WriteContextRenames the last key element of a given path.- Specified by:
renameKeyin interfaceWriteContext- Parameters:
path- 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.- Returns:
- a document content.
-
renameKey
public DocumentContext renameKey(JsonPath path, java.lang.String oldKeyName, java.lang.String newKeyName)
Description copied from interface:WriteContextRenames the last key element of a given path.- Specified by:
renameKeyin interfaceWriteContext- Parameters:
path- 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.- Returns:
- a document content.
-
put
public DocumentContext put(JsonPath path, java.lang.String key, java.lang.Object value)
Description copied from interface:WriteContextAdd or update the key with a the given value at the given path- Specified by:
putin interfaceWriteContext- Parameters:
path- path to arraykey- key to addvalue- value of key- Returns:
- a document context
-
-