|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jayway.jsonpath.JsonModel
public class JsonModel
A JsonModel holds a parsed JSON document and provides easy read and write operations. In contrast to the
static read operations provided by JsonPath a JsonModel will only parse the document once.
| Nested Class Summary | |
|---|---|
static interface |
JsonModel.ArrayOps
Operations that can be performed on Json arrays ( Lists) |
static interface |
JsonModel.ListMappingModelReader
Converts a JsonModel to an Collection of Objects |
static interface |
JsonModel.MappingModelReader
Object mapping interface used when for root object that can be either a List or a Map. |
static interface |
JsonModel.ObjectMappingModelReader
Converts a JsonModel to an Object |
static interface |
JsonModel.ObjectOps
Operations that can be performed on Json objects ( Maps) |
| Method Summary | ||
|---|---|---|
static JsonModel |
create(InputStream jsonInputStream)
|
|
static JsonModel |
create(Object jsonObject)
|
|
static JsonModel |
create(String json)
|
|
static JsonModel |
create(URL url)
|
|
|
get(JsonPath jsonPath)
Reads the given path from this JsonModel. |
|
|
get(String jsonPath,
Filter... filters)
Reads the given path from this JsonModel. |
|
Object |
getJsonObject()
Returns the root object of this JsonModel |
|
JsonModel |
getSubModel(JsonPath jsonPath)
Returns a sub model from this JsonModel. |
|
JsonModel |
getSubModel(String jsonPath)
Returns a sub model from this JsonModel. |
|
JsonModel |
getSubModelDetached(JsonPath jsonPath)
Creates a detached sub model from this JsonModel. |
|
JsonModel |
getSubModelDetached(String jsonPath,
Filter... filters)
Creates a detached sub model from this JsonModel. |
|
boolean |
hasPath(JsonPath jsonPath)
Check if this JsonModel has the given definite path |
|
boolean |
hasPath(String jsonPath)
Check if this JsonModel has the given definite path |
|
boolean |
isList()
Check if this JsonModel is holding a JSON array as to object |
|
boolean |
isMap()
Check if this JsonModel is holding a JSON object as to object |
|
JsonModel.MappingModelReader |
map()
Returns a JsonModel.ObjectMappingModelReader for this JsonModel. |
|
JsonModel.MappingModelReader |
map(JsonPath jsonPath)
Returns a JsonModel.ObjectMappingModelReader for the JsonModel targeted by the provided JsonPath. |
|
JsonModel.MappingModelReader |
map(String jsonPath,
Filter... filters)
Returns a JsonModel.ObjectMappingModelReader for the JsonModel targeted by the provided JsonPath. |
|
static JsonModel |
model(InputStream jsonInputStream)
Creates a JsonModel |
|
static JsonModel |
model(Object jsonObject)
Creates a JsonModel |
|
static JsonModel |
model(String json)
Creates a JsonModel |
|
static JsonModel |
model(URL url)
Creates a JsonModel |
|
JsonModel.ArrayOps |
opsForArray()
Gets an JsonModel.ArrayOps for this JsonModel. |
|
JsonModel.ArrayOps |
opsForArray(JsonPath jsonPath)
Gets an JsonModel.ArrayOps for the array inside this JsonModel identified by the given JsonPath. |
|
JsonModel.ArrayOps |
opsForArray(String jsonPath)
Gets an JsonModel.ArrayOps for the array inside this JsonModel identified by the given JsonPath. |
|
JsonModel.ObjectOps |
opsForObject()
Gets an JsonModel.ObjectOps for this JsonModel. |
|
JsonModel.ObjectOps |
opsForObject(JsonPath jsonPath)
Gets an JsonModel.ObjectOps for the object inside this JsonModel identified by the given JsonPath. |
|
JsonModel.ObjectOps |
opsForObject(String jsonPath)
Gets an JsonModel.ObjectOps for the object inside this JsonModel identified by the given JsonPath. |
|
void |
print()
Prints this JsonModel to standard out |
|
String |
toJson()
Creates a JSON representation of this JsonModel |
|
String |
toJson(boolean prettyPrint)
Creates a JSON representation of this JsonModel |
|
String |
toJson(JsonPath jsonPath)
Creates a JSON representation of the result of the provided JsonPath |
|
String |
toJson(String jsonPath,
Filter... filters)
Creates a JSON representation of the result of the provided JsonPath |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public boolean isList()
public boolean isMap()
public void print()
public boolean hasPath(String jsonPath)
jsonPath - path to check
JsonPath.isPathDefinite()public boolean hasPath(JsonPath jsonPath)
jsonPath - path to check
JsonPath.isPathDefinite()public Object getJsonObject()
public <T> T get(String jsonPath,
Filter... filters)
JsonModel model = JsonModel.model(myJson);
//A
List books = model.read("$store.book[?(@author == 'Nigel Rees')]");
//B
List books = model.read("$store.book[?]", filter(where("author").is("Nigel Rees"));
//C
JsonPath path = JsonPath.compile("$store.book[?]", filter(where("author").is("Nigel Rees"));
List books = model.read(path);
The filters are applied in the order they are provided. If a path contains multiple [?] filter markers
the filters must be passed in the correct order.
T - expected return typejsonPath - the path to readfilters - filters to use in the path
Filter,
Criteriapublic <T> T get(JsonPath jsonPath)
T - expected return typejsonPath - the path to read
public JsonModel.ArrayOps opsForArray()
JsonModel.ArrayOps for this JsonModel. Note that the root element of this model
must be a json array.
public JsonModel.ArrayOps opsForArray(String jsonPath)
JsonModel.ArrayOps for the array inside this JsonModel identified by the given JsonPath. The path must
be definite (JsonPath.isPathDefinite()).
Note that the element returned by the given path must be a json array.
jsonPath - definite path to array to perform operations on
public JsonModel.ArrayOps opsForArray(JsonPath jsonPath)
JsonModel.ArrayOps for the array inside this JsonModel identified by the given JsonPath. The path must
be definite (JsonPath.isPathDefinite()).
Note that the element returned by the given path must be a json array.
jsonPath - definite path to array to perform operations on
public JsonModel.ObjectOps opsForObject()
JsonModel.ObjectOps for this JsonModel. Note that the root element of this model
must be a json object.
public JsonModel.ObjectOps opsForObject(String jsonPath)
JsonModel.ObjectOps for the object inside this JsonModel identified by the given JsonPath. The path must
be definite (JsonPath.isPathDefinite()).
Note that the element returned by the given path must be a json object.
jsonPath - definite path to object to perform operations on
public JsonModel.ObjectOps opsForObject(JsonPath jsonPath)
JsonModel.ObjectOps for the object inside this JsonModel identified by the given JsonPath. The path must
be definite (JsonPath.isPathDefinite()).
Note that the element returned by the given path must be a json object.
jsonPath - definite path to object to perform operations on
public String toJson()
public String toJson(boolean prettyPrint)
prettyPrint - if the model should be pretty printed
public String toJson(String jsonPath,
Filter... filters)
public String toJson(JsonPath jsonPath)
public JsonModel getSubModel(String jsonPath)
jsonPath - the absolute path to extract a JsonModel for
JsonPath.isPathDefinite()public JsonModel getSubModel(JsonPath jsonPath)
jsonPath - the absolute path to extract a JsonModel for
JsonPath.isPathDefinite()
public JsonModel getSubModelDetached(String jsonPath,
Filter... filters)
jsonPath - the absolute path to extract a JsonModel forfilters - filters to expand the path
public JsonModel getSubModelDetached(JsonPath jsonPath)
jsonPath - the absolute path to extract a JsonModel for
public JsonModel.MappingModelReader map()
JsonModel.ObjectMappingModelReader for this JsonModel. Note that to use this functionality you need
an optional dependencies on your classpath (jackson-mapper-asl ver >= 1.9.5)
public JsonModel.MappingModelReader map(String jsonPath,
Filter... filters)
JsonModel.ObjectMappingModelReader for the JsonModel targeted by the provided JsonPath. Note that to use this functionality you need
an optional dependencies on your classpath (jackson-mapper-asl ver >= 1.9.5)
public JsonModel.MappingModelReader map(JsonPath jsonPath)
JsonModel.ObjectMappingModelReader for the JsonModel targeted by the provided JsonPath. Note that to use this functionality you need
an optional dependencies on your classpath (jackson-mapper-asl ver >= 1.9.5)
public static JsonModel model(String json)
json - json string
public static JsonModel create(String json)
public static JsonModel model(Object jsonObject)
jsonObject - a json container (a Map or a List)
public static JsonModel create(Object jsonObject)
public static JsonModel model(URL url)
throws IOException
url - pointing to a Json document
IOException
public static JsonModel create(URL url)
throws IOException
IOException
public static JsonModel model(InputStream jsonInputStream)
throws IOException
jsonInputStream - json document stream
IOException
public static JsonModel create(InputStream jsonInputStream)
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||