Package com.jayway.jsonpath.internal
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 Configuration
private Object
private static final org.slf4j.Logger
-
Constructor Summary
ConstructorsModifierConstructorDescriptionJsonContext
(Configuration configuration) private
JsonContext
(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> T
convert
(Object obj, TypeRef<T> targetType, Configuration configuration) private <T> T
convert
(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> T
Reads the given path from this context<T> T
Reads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRefinvalid input: '<'List
>() {}; <T> T
Reads the given path from this context<T> T
Reads the given path from this context<T> T
Reads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRefinvalid input: '<'List
>() {}; <T> T
Reads 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:
parse
in interfaceParseContext
-
parse
- Specified by:
parse
in interfaceParseContext
-
parse
- Specified by:
parse
in interfaceParseContext
-
parse
- Specified by:
parse
in interfaceParseContext
-
parse
- Specified by:
parse
in interfaceParseContext
- Throws:
IOException
-
configuration
Description copied from interface:ReadContext
Returns the configuration used for reading- Specified by:
configuration
in interfaceReadContext
- Specified by:
configuration
in interfaceWriteContext
- Returns:
- an immutable configuration
-
json
Description copied from interface:ReadContext
Returns the JSON model that this context is operating on- Specified by:
json
in interfaceReadContext
- Specified by:
json
in interfaceWriteContext
- Returns:
- json model
-
jsonString
Description copied from interface:ReadContext
Returns the JSON model that this context is operating on as a JSON string- Specified by:
jsonString
in interfaceReadContext
- Specified by:
jsonString
in interfaceWriteContext
- Returns:
- json model as string
-
read
Description copied from interface:ReadContext
Reads the given path from this context- Specified by:
read
in interfaceReadContext
- Type Parameters:
T
-- Parameters:
path
- path to readfilters
- filters- Returns:
- result
-
read
Description copied from interface:ReadContext
Reads the given path from this context- Specified by:
read
in 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:ReadContext
Reads the given path from this context- Specified by:
read
in interfaceReadContext
- Type Parameters:
T
-- Parameters:
path
- path to apply- Returns:
- result
-
read
Description copied from interface:ReadContext
Reads the given path from this context- Specified by:
read
in interfaceReadContext
- Type Parameters:
T
-- Parameters:
path
- path to applytype
- expected return type (will try to map)- Returns:
- result
-
read
Description copied from interface:ReadContext
Reads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRefinvalid input: '<'List
>() {}; - Specified by:
read
in interfaceReadContext
- Type Parameters:
T
-- Parameters:
path
- path to applytype
- expected return type (will try to map)- Returns:
- result
-
read
Description copied from interface:ReadContext
Reads the given path from this context Sample code to create a TypeRefTypeRef ref = new TypeRefinvalid input: '<'List
>() {}; - Specified by:
read
in interfaceReadContext
- Type Parameters:
T
-- Parameters:
path
- path to applytype
- expected return type (will try to map)- Returns:
- result
-
limit
Description copied from interface:ReadContext
Stops evaluation when maxResults limit has been reached- Specified by:
limit
in interfaceReadContext
- Parameters:
maxResults
-- Returns:
- the read context
-
withListeners
Description copied from interface:ReadContext
Adds listener to the evaluation of this path- Specified by:
withListeners
in interfaceReadContext
- Parameters:
listener
- listeners to add- Returns:
- the read context
-
convert
-
convert
-
set
Description copied from interface:WriteContext
Set the value a the given path- Specified by:
set
in interfaceWriteContext
- Parameters:
path
- path to setnewValue
- new valuefilters
- filters- Returns:
- a document context
-
set
Description copied from interface:WriteContext
Set the value a the given path- Specified by:
set
in interfaceWriteContext
- Parameters:
path
- path to setnewValue
- new value- Returns:
- a document context
-
map
Description copied from interface:WriteContext
Replaces the value on the given path with the result of theMapFunction
.- Specified by:
map
in interfaceWriteContext
- Parameters:
path
- path to be converted setmapFunction
- Converter object to be invokedfilters
- filters- Returns:
- a document context
-
map
Description copied from interface:WriteContext
Replaces the value on the given path with the result of theMapFunction
.- Specified by:
map
in interfaceWriteContext
- Parameters:
path
- path to be converted setmapFunction
- Converter object to be invoked (or lambda:))- Returns:
- a document context
-
delete
Description copied from interface:WriteContext
Deletes the given path- Specified by:
delete
in interfaceWriteContext
- Parameters:
path
- path to deletefilters
- filters- Returns:
- a document context
-
delete
Description copied from interface:WriteContext
Deletes the given path- Specified by:
delete
in interfaceWriteContext
- Parameters:
path
- path to delete- Returns:
- a document context
-
add
Description copied from interface:WriteContext
Add value to arrayList
array = new ArrayList (){{ add(0); add(1); }}; JsonPath.parse(array).add("$", 2); assertThat(array).containsExactly(0,1,2); - Specified by:
add
in interfaceWriteContext
- Parameters:
path
- path to arrayvalue
- value to addfilters
- filters- Returns:
- a document context
-
add
Description copied from interface:WriteContext
Add value to array at the given path- Specified by:
add
in interfaceWriteContext
- Parameters:
path
- path to arrayvalue
- value to add- Returns:
- a document context
-
put
Description copied from interface:WriteContext
Add or update the key with a the given value at the given path- Specified by:
put
in 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:WriteContext
Renames the last key element of a given path.- Specified by:
renameKey
in 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:WriteContext
Renames the last key element of a given path.- Specified by:
renameKey
in 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:WriteContext
Add or update the key with a the given value at the given path- Specified by:
put
in interfaceWriteContext
- Parameters:
path
- path to arraykey
- key to addvalue
- value of key- Returns:
- a document context
-