Modifier and Type | Class and Description |
---|---|
static interface |
JsonModel.ArrayOps
Operations that can be performed on Json arrays (
List s) |
static interface |
JsonModel.ListMappingModelReader
Converts a
JsonModel to an Collection of Objects |
static interface |
JsonModel.MappingModelReader
|
static interface |
JsonModel.ObjectMappingModelReader
Converts a
JsonModel to an Object |
static interface |
JsonModel.ObjectOps
Operations that can be performed on Json objects (
Map s) |
Modifier and Type | Method and Description |
---|---|
static JsonModel |
create(InputStream jsonInputStream) |
static JsonModel |
create(Object jsonObject) |
static JsonModel |
create(String json) |
static JsonModel |
create(URL url) |
<T> T |
get(JsonPath jsonPath)
Reads the given path from this JsonModel.
|
<T> T |
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.MappingModelReader for this JsonModel. |
JsonModel.MappingModelReader |
map(JsonPath jsonPath)
Returns a
JsonModel.MappingModelReader for the JsonModel targeted by the provided JsonPath . |
JsonModel.MappingModelReader |
map(String jsonPath,
Filter... filters)
Returns a
JsonModel.MappingModelReader for the JsonModel targeted by the provided JsonPath . |
static JsonModel |
model(InputStream jsonInputStream)
Creates a JsonModel
|
static JsonModel |
model(JsonProvider jsonProvider,
InputStream jsonInputStream)
Creates a JsonModel
|
static JsonModel |
model(JsonProvider jsonProvider,
Object jsonObject)
Creates a JsonModel
|
static JsonModel |
model(JsonProvider jsonProvider,
String json)
Creates a JsonModel
|
static JsonModel |
model(JsonProvider jsonProvider,
URL url)
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
|
public boolean isList()
public boolean isMap()
public void print()
public boolean hasPath(String jsonPath)
jsonPath
- path to checkJsonPath.isPathDefinite()
public boolean hasPath(JsonPath jsonPath)
jsonPath
- path to checkJsonPath.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.public <T> T get(JsonPath jsonPath)
T
- expected return typejsonPath
- the path to readpublic 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 onpublic 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 onpublic 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 onpublic 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 onpublic String toJson()
public String toJson(boolean prettyPrint)
prettyPrint
- if the model should be pretty printedpublic String toJson(String jsonPath, Filter... filters)
public String toJson(JsonPath jsonPath)
public JsonModel getSubModel(String jsonPath)
jsonPath
- the absolute path to extract a JsonModel forJsonPath.isPathDefinite()
public JsonModel getSubModel(JsonPath jsonPath)
jsonPath
- the absolute path to extract a JsonModel forJsonPath.isPathDefinite()
public JsonModel getSubModelDetached(String jsonPath, Filter... filters)
jsonPath
- the absolute path to extract a JsonModel forfilters
- filters to expand the pathpublic JsonModel getSubModelDetached(JsonPath jsonPath)
jsonPath
- the absolute path to extract a JsonModel forpublic JsonModel.MappingModelReader map()
JsonModel.MappingModelReader
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.MappingModelReader
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.MappingModelReader
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(JsonProvider jsonProvider, String json)
jsonProvider
- JsonProvider to usejson
- json stringpublic static JsonModel model(String json)
json
- json stringpublic static JsonModel model(JsonProvider jsonProvider, Object jsonObject)
public static JsonModel model(JsonProvider jsonProvider, URL url) throws IOException
jsonProvider
- JsonProvider to useurl
- pointing to a Json documentIOException
public static JsonModel model(URL url) throws IOException
url
- pointing to a Json documentIOException
public static JsonModel create(URL url) throws IOException
IOException
public static JsonModel model(JsonProvider jsonProvider, InputStream jsonInputStream) throws IOException
jsonProvider
- JsonProvider to usejsonInputStream
- json document streamIOException
public static JsonModel model(InputStream jsonInputStream) throws IOException
jsonInputStream
- json document streamIOException
public static JsonModel create(InputStream jsonInputStream) throws IOException
IOException
Copyright © 2011–2013. All rights reserved.