public class JsonContext extends Object implements ParseContext, DocumentContext
Constructor and Description |
---|
JsonContext() |
JsonContext(Configuration configuration) |
Modifier and Type | Method and Description |
---|---|
DocumentContext |
add(JsonPath path,
Object value)
Add value to array at the given path
|
DocumentContext |
add(String path,
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(String path,
Predicate... filters)
Deletes the given path
|
Object |
json()
Returns the JSON model that this context is operating on
|
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(String path,
MapFunction mapFunction,
Predicate... filters)
Replaces the value on the given path with the result of the
MapFunction . |
DocumentContext |
parse(File json) |
DocumentContext |
parse(InputStream json) |
DocumentContext |
parse(InputStream json,
String charset) |
DocumentContext |
parse(Object json) |
DocumentContext |
parse(String json) |
DocumentContext |
put(JsonPath path,
String key,
Object value)
Add or update the key with a the given value at the given path
|
DocumentContext |
put(String path,
String key,
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,
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(String path,
Class<T> type,
Predicate... filters)
Reads the given path from this context
|
<T> T |
read(String path,
Predicate... filters)
Reads the given path from this context
|
<T> T |
read(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,
String oldKeyName,
String newKeyName)
Renames the last key element of a given path.
|
DocumentContext |
renameKey(String path,
String oldKeyName,
String newKeyName,
Predicate... filters)
Renames the last key element of a given path.
|
DocumentContext |
set(JsonPath path,
Object newValue)
Set the value a the given path
|
DocumentContext |
set(String path,
Object newValue,
Predicate... filters)
Set the value a the given path
|
ReadContext |
withListeners(EvaluationListener... listener)
Adds listener to the evaluation of this path
|
public JsonContext()
public JsonContext(Configuration configuration)
public DocumentContext parse(Object json)
parse
in interface ParseContext
public DocumentContext parse(String json)
parse
in interface ParseContext
public DocumentContext parse(InputStream json)
parse
in interface ParseContext
public DocumentContext parse(InputStream json, String charset)
parse
in interface ParseContext
public DocumentContext parse(File json) throws IOException
parse
in interface ParseContext
IOException
public Configuration configuration()
ReadContext
configuration
in interface ReadContext
configuration
in interface WriteContext
public Object json()
ReadContext
json
in interface ReadContext
json
in interface WriteContext
public String jsonString()
ReadContext
jsonString
in interface ReadContext
jsonString
in interface WriteContext
public <T> T read(String path, Predicate... filters)
ReadContext
read
in interface ReadContext
path
- path to readfilters
- filterspublic <T> T read(String path, Class<T> type, Predicate... filters)
ReadContext
read
in interface ReadContext
path
- path to readtype
- expected return type (will try to map)filters
- filterspublic <T> T read(JsonPath path)
ReadContext
read
in interface ReadContext
path
- path to applypublic <T> T read(JsonPath path, Class<T> type)
ReadContext
read
in interface ReadContext
path
- 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 ReadContext
path
- path to applytype
- expected return type (will try to map)public <T> T read(String path, TypeRef<T> type)
ReadContext
TypeRef ref = new TypeRef>() {};
read
in interface ReadContext
path
- path to applytype
- expected return type (will try to map)public ReadContext limit(int maxResults)
ReadContext
limit
in interface ReadContext
public ReadContext withListeners(EvaluationListener... listener)
ReadContext
withListeners
in interface ReadContext
listener
- listeners to addpublic DocumentContext set(String path, Object newValue, Predicate... filters)
WriteContext
set
in interface WriteContext
path
- path to setnewValue
- new valuefilters
- filterspublic DocumentContext set(JsonPath path, Object newValue)
WriteContext
set
in interface WriteContext
path
- path to setnewValue
- new valuepublic DocumentContext map(String path, MapFunction mapFunction, Predicate... filters)
WriteContext
MapFunction
.map
in interface WriteContext
path
- path to be converted setmapFunction
- Converter object to be invokedfilters
- filterspublic DocumentContext map(JsonPath path, MapFunction mapFunction)
WriteContext
MapFunction
.map
in interface WriteContext
path
- path to be converted setmapFunction
- Converter object to be invoked (or lambda:))public DocumentContext delete(String path, Predicate... filters)
WriteContext
delete
in interface WriteContext
path
- path to deletefilters
- filterspublic DocumentContext delete(JsonPath path)
WriteContext
delete
in interface WriteContext
path
- path to deletepublic DocumentContext add(String path, 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 WriteContext
path
- path to arrayvalue
- value to addfilters
- filterspublic DocumentContext add(JsonPath path, Object value)
WriteContext
add
in interface WriteContext
path
- path to arrayvalue
- value to addpublic DocumentContext put(String path, String key, Object value, Predicate... filters)
WriteContext
put
in interface WriteContext
path
- path to objectkey
- key to addvalue
- value of keyfilters
- filterspublic DocumentContext renameKey(String path, String oldKeyName, String newKeyName, Predicate... filters)
WriteContext
renameKey
in interface WriteContext
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.public DocumentContext renameKey(JsonPath path, String oldKeyName, String newKeyName)
WriteContext
renameKey
in interface WriteContext
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.public DocumentContext put(JsonPath path, String key, Object value)
WriteContext
put
in interface WriteContext
path
- path to arraykey
- key to addvalue
- value of keyCopyright © 2016. All rights reserved.