public class JsonReader extends java.lang.Object implements ParseContext, DocumentContext
| Constructor and Description |
|---|
JsonReader() |
JsonReader(Configuration configuration) |
| 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 |
parse(java.io.File json) |
DocumentContext |
parse(java.io.InputStream json) |
DocumentContext |
parse(java.io.InputStream json,
java.lang.String charset) |
DocumentContext |
parse(java.lang.Object json) |
DocumentContext |
parse(java.lang.String json) |
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 |
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 JsonReader()
public JsonReader(Configuration configuration)
public DocumentContext parse(java.lang.Object json)
parse in interface ParseContextpublic DocumentContext parse(java.lang.String json)
parse in interface ParseContextpublic DocumentContext parse(java.io.InputStream json)
parse in interface ParseContextpublic DocumentContext parse(java.io.InputStream json, java.lang.String charset)
parse in interface ParseContextpublic DocumentContext parse(java.io.File json) throws java.io.IOException
parse in interface ParseContextjava.io.IOExceptionpublic 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 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 put(JsonPath path, java.lang.String key, java.lang.Object value)
WriteContextput in interface WriteContextpath - path to arraykey - key to addvalue - value of key