public class SimpleCachedJsonValueExtractor
extends java.lang.Object
String jsonSource = "{\"testArray\":[1,2,3, {\"A\":5,\"B\":7},\"X\"], \"tail\":9}";
String simpleQuery = "testArray.[3].A";
SimpleCachedJsonValueExtractor cachedJsonValueExtractor = new SimpleCachedJsonValueExtractor(jsonSource);
if (cachedJsonValueExtractor.containsQuery(simpleQuery)) {
JsonValue queryResult = cachedJsonValueExtractor.getQueryResult(simpleQuery);
if (queryResult == null) {
System.out.println("Query Result = Json null value");
}
else {
System.out.println("Query Result = " + queryResult.toString()); // 5
}
}
else {
System.out.println("[No match found]");
}
| Constructor and Description |
|---|
SimpleCachedJsonValueExtractor(java.io.Reader jsonReader)
Create a new instance from a Json Reader and initialize the cache.
|
SimpleCachedJsonValueExtractor(java.lang.String jsonSource)
Create a new instance from a Json String and initialize the cache.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsQuery(java.lang.String simpleQuery)
Get if the cache contains a result of a simple query.
|
JsonValue |
getQueryResult(java.lang.String simpleQuery)
Get the simple Json value (String, long, boolean or null).
|
public SimpleCachedJsonValueExtractor(java.lang.String jsonSource)
jsonSource - a String containing the Json datajava.lang.IllegalArgumentException - if the root of the Json data is not an Object or Arraypublic SimpleCachedJsonValueExtractor(java.io.Reader jsonReader)
throws java.io.IOException
jsonReader - a Reader for the Json datajava.lang.IllegalArgumentException - if the root of the Json data is not an Object or Arrayjava.io.IOException - if somewhat fails.public boolean containsQuery(java.lang.String simpleQuery)
simpleQuery - the simple query. Examples: "[0].datapoints.[2].[1]", "customers.person.name"public JsonValue getQueryResult(java.lang.String simpleQuery)
simpleQuery - the simple query. Examples: "[0].datapoints.[2].[1]", "customers.person.name"