Class JsonContext
java.lang.Object
com.jayway.jsonpath.internal.JsonContext
- All Implemented Interfaces:
DocumentContext, ParseContext, ReadContext, WriteContext
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Configurationprivate Objectprivate static final org.slf4j.Logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionJsonContext(Configuration configuration) privateJsonContext(Object json, Configuration configuration) -
Method Summary
Modifier and TypeMethodDescriptionAdd value to array at the given pathAdd value to arrayReturns the configuration used for readingprivate <T> Tconvert(Object obj, TypeRef<T> targetType, Configuration configuration) private <T> Tconvert(Object obj, Class<T> targetType, Configuration configuration) Deletes the given pathDeletes the given pathjson()Returns the JSON model that this context is operating onReturns the JSON model that this context is operating on as a JSON stringlimit(int maxResults) Stops evaluation when maxResults limit has been reachedmap(JsonPath path, MapFunction mapFunction) Replaces the value on the given path with the result of theMapFunction.map(String path, MapFunction mapFunction, Predicate... filters) Replaces the value on the given path with the result of theMapFunction.parse(InputStream json) parse(InputStream json, String charset) Add or update the key with a the given value at the given pathAdd or update the key with a the given value at the given path<T> TReads the given path from this context<T> TReads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRefinvalid input: '<'List>() {}; <T> TReads the given path from this context<T> TReads the given path from this context<T> TReads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRefinvalid input: '<'List>() {}; <T> TReads the given path from this contextRenames the last key element of a given path.Renames the last key element of a given path.Set the value a the given pathSet the value a the given pathwithListeners(EvaluationListener... listener) Adds listener to the evaluation of this path
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
configuration
-
json
-
-
Constructor Details
-
JsonContext
public JsonContext() -
JsonContext
-
JsonContext
-
-
Method Details
-
parse
- Specified by:
parsein interfaceParseContext
-
parse
- Specified by:
parsein interfaceParseContext
-
parse
- Specified by:
parsein interfaceParseContext
-
parse
- Specified by:
parsein interfaceParseContext
-
parse
- Specified by:
parsein interfaceParseContext- Throws:
IOException
-
configuration
Description copied from interface:ReadContextReturns the configuration used for reading- Specified by:
configurationin interfaceReadContext- Specified by:
configurationin interfaceWriteContext- Returns:
- an immutable configuration
-
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
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
Description copied from interface:ReadContextReads the given path from this context- Specified by:
readin interfaceReadContext- Type Parameters:
T-- Parameters:
path- path to readfilters- filters- Returns:
- result
-
read
Description copied from interface:ReadContextReads the given path from this context- Specified by:
readin interfaceReadContext- Type Parameters:
T-- Parameters:
path- path to readtype- expected return type (will try to map)filters- filters- Returns:
- result
-
read
Description copied from interface:ReadContextReads the given path from this context- Specified by:
readin interfaceReadContext- Type Parameters:
T-- Parameters:
path- path to apply- Returns:
- result
-
read
Description copied from interface:ReadContextReads the given path from this context- Specified by:
readin interfaceReadContext- Type Parameters:
T-- Parameters:
path- path to applytype- expected return type (will try to map)- Returns:
- result
-
read
Description copied from interface:ReadContextReads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRefinvalid input: '<'List>() {}; - Specified by:
readin interfaceReadContext- Type Parameters:
T-- Parameters:
path- path to applytype- expected return type (will try to map)- Returns:
- result
-
read
Description copied from interface:ReadContextReads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRefinvalid input: '<'List>() {}; - Specified by:
readin interfaceReadContext- Type Parameters:
T-- Parameters:
path- path to applytype- expected return type (will try to map)- Returns:
- result
-
limit
Description copied from interface:ReadContextStops evaluation when maxResults limit has been reached- Specified by:
limitin interfaceReadContext- Parameters:
maxResults-- Returns:
- the read context
-
withListeners
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
-
convert
-
convert
-
set
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
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
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
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
Description copied from interface:WriteContextDeletes the given path- Specified by:
deletein interfaceWriteContext- Parameters:
path- path to deletefilters- filters- Returns:
- a document context
-
delete
Description copied from interface:WriteContextDeletes the given path- Specified by:
deletein interfaceWriteContext- Parameters:
path- path to delete- Returns:
- a document context
-
add
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
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
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(String path, String oldKeyName, 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
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
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
-