|
|
@ -16,13 +16,13 @@ package com.jayway.jsonpath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jayway.jsonpath.internal.IOUtils; |
|
|
|
import com.jayway.jsonpath.internal.IOUtils; |
|
|
|
|
|
|
|
import com.jayway.jsonpath.internal.JsonReader; |
|
|
|
import com.jayway.jsonpath.internal.PathToken; |
|
|
|
import com.jayway.jsonpath.internal.PathToken; |
|
|
|
import com.jayway.jsonpath.internal.PathTokenizer; |
|
|
|
import com.jayway.jsonpath.internal.PathTokenizer; |
|
|
|
import com.jayway.jsonpath.internal.filter.PathTokenFilter; |
|
|
|
import com.jayway.jsonpath.internal.filter.PathTokenFilter; |
|
|
|
import com.jayway.jsonpath.spi.HttpProviderFactory; |
|
|
|
import com.jayway.jsonpath.spi.HttpProviderFactory; |
|
|
|
import com.jayway.jsonpath.spi.JsonProvider; |
|
|
|
import com.jayway.jsonpath.spi.JsonProvider; |
|
|
|
import com.jayway.jsonpath.spi.JsonProviderFactory; |
|
|
|
import com.jayway.jsonpath.spi.JsonProviderFactory; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -137,7 +137,8 @@ public class JsonPath { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JsonPath copy() { |
|
|
|
public JsonPath copy() { |
|
|
|
return new JsonPath(tokenizer.getPath(), filters.toArray(new Filter[0])); |
|
|
|
Filter[] filterCopy = filters.isEmpty()?new Filter[0]:new Filter[filters.size()]; |
|
|
|
|
|
|
|
return new JsonPath(tokenizer.getPath(), filters.toArray(filterCopy)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -212,7 +213,7 @@ public class JsonPath { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(Object jsonObject) { |
|
|
|
public <T> T read(Object jsonObject) { |
|
|
|
return read(JsonProviderFactory.createProvider(), jsonObject); |
|
|
|
return read(jsonObject, Configuration.defaultConfiguration()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -220,22 +221,21 @@ public class JsonPath { |
|
|
|
* Note that the document must be identified as either a List or Map by |
|
|
|
* Note that the document must be identified as either a List or Map by |
|
|
|
* the {@link JsonProvider} |
|
|
|
* the {@link JsonProvider} |
|
|
|
* |
|
|
|
* |
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
|
|
|
|
* @param jsonObject a container Object |
|
|
|
* @param jsonObject a container Object |
|
|
|
|
|
|
|
* @param configuration configuration to use |
|
|
|
* @param <T> expected return type |
|
|
|
* @param <T> expected return type |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @return list of objects matched by the given path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(Object jsonObject, Configuration configuration) { |
|
|
|
public <T> T read(JsonProvider jsonProvider, Object jsonObject) { |
|
|
|
|
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notNull(jsonObject, "json can not be null"); |
|
|
|
notNull(jsonObject, "json can not be null"); |
|
|
|
|
|
|
|
notNull(configuration, "configuration can not be null"); |
|
|
|
|
|
|
|
|
|
|
|
if (this.getPath().equals("$")) { |
|
|
|
if (this.getPath().equals("$")) { |
|
|
|
//This path only references the whole object. No need to do any work here...
|
|
|
|
//This path only references the whole object. No need to do any work here...
|
|
|
|
return (T) jsonObject; |
|
|
|
return (T) jsonObject; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!jsonProvider.isContainer(jsonObject)) { |
|
|
|
if (!configuration.getProvider().isContainer(jsonObject)) { |
|
|
|
throw new IllegalArgumentException("Invalid container object"); |
|
|
|
throw new IllegalArgumentException("Invalid container object"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -253,12 +253,13 @@ public class JsonPath { |
|
|
|
LOG.debug("Applying filter: " + filter + " to " + result); |
|
|
|
LOG.debug("Applying filter: " + filter + " to " + result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result = filter.filter(result, jsonProvider, contextFilters, inArrayContext); |
|
|
|
result = filter.filter(result, configuration, contextFilters, inArrayContext); |
|
|
|
|
|
|
|
|
|
|
|
//TODO: finalize behaviour
|
|
|
|
/* |
|
|
|
if(result == null && !pathToken.isEndToken()){ |
|
|
|
if(result == null && !pathToken.isEndToken()){ |
|
|
|
throw new PathNotFoundException("AAAAAA"); |
|
|
|
throw new PathNotFoundException("Path token: " + pathToken.getFragment() + " not found in json"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
if (!inArrayContext) { |
|
|
|
if (!inArrayContext) { |
|
|
|
inArrayContext = filter.isArrayFilter(); |
|
|
|
inArrayContext = filter.isArrayFilter(); |
|
|
@ -276,23 +277,23 @@ public class JsonPath { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(String json) { |
|
|
|
public <T> T read(String json) { |
|
|
|
return read(JsonProviderFactory.createProvider(), json); |
|
|
|
return read(json, Configuration.defaultConfiguration()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Applies this JsonPath to the provided json string |
|
|
|
* Applies this JsonPath to the provided json string |
|
|
|
* |
|
|
|
* |
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
|
|
|
|
* @param json a json string |
|
|
|
* @param json a json string |
|
|
|
|
|
|
|
* @param configuration configuration to use |
|
|
|
* @param <T> expected return type |
|
|
|
* @param <T> expected return type |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @return list of objects matched by the given path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(JsonProvider jsonProvider, String json) { |
|
|
|
public <T> T read(String json, Configuration configuration) { |
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notEmpty(json, "json can not be null or empty"); |
|
|
|
notEmpty(json, "json can not be null or empty"); |
|
|
|
|
|
|
|
notNull(configuration, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
|
|
|
|
return read(jsonProvider, jsonProvider.parse(json)); |
|
|
|
return read(configuration.getProvider().parse(json), configuration); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -305,27 +306,27 @@ public class JsonPath { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(URL jsonURL) throws IOException { |
|
|
|
public <T> T read(URL jsonURL) throws IOException { |
|
|
|
return read(JsonProviderFactory.createProvider(), jsonURL); |
|
|
|
return read(jsonURL, Configuration.defaultConfiguration()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Applies this JsonPath to the provided json URL |
|
|
|
* Applies this JsonPath to the provided json URL |
|
|
|
* |
|
|
|
* |
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
|
|
|
|
* @param jsonURL url to read from |
|
|
|
* @param jsonURL url to read from |
|
|
|
|
|
|
|
* @param configuration configuration to use |
|
|
|
* @param <T> expected return type |
|
|
|
* @param <T> expected return type |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @throws IOException |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(JsonProvider jsonProvider, URL jsonURL) throws IOException { |
|
|
|
public <T> T read(URL jsonURL, Configuration configuration) throws IOException { |
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notNull(jsonURL, "json URL can not be null"); |
|
|
|
notNull(jsonURL, "json URL can not be null"); |
|
|
|
|
|
|
|
notNull(configuration, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
|
|
|
|
InputStream in = null; |
|
|
|
InputStream in = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
in = HttpProviderFactory.getProvider().get(jsonURL); |
|
|
|
in = HttpProviderFactory.getProvider().get(jsonURL); |
|
|
|
return read(jsonProvider, jsonProvider.parse(in)); |
|
|
|
return read(configuration.getProvider().parse(in), configuration); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
IOUtils.closeQuietly(in); |
|
|
|
IOUtils.closeQuietly(in); |
|
|
|
} |
|
|
|
} |
|
|
@ -341,29 +342,29 @@ public class JsonPath { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(File jsonFile) throws IOException { |
|
|
|
public <T> T read(File jsonFile) throws IOException { |
|
|
|
return read(JsonProviderFactory.createProvider(), jsonFile); |
|
|
|
return read(jsonFile, Configuration.defaultConfiguration()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Applies this JsonPath to the provided json file |
|
|
|
* Applies this JsonPath to the provided json file |
|
|
|
* |
|
|
|
* |
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
|
|
|
|
* @param jsonFile file to read from |
|
|
|
* @param jsonFile file to read from |
|
|
|
|
|
|
|
* @param configuration configuration to use |
|
|
|
* @param <T> expected return type |
|
|
|
* @param <T> expected return type |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @throws IOException |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(JsonProvider jsonProvider, File jsonFile) throws IOException { |
|
|
|
public <T> T read(File jsonFile, Configuration configuration) throws IOException { |
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notNull(jsonFile, "json file can not be null"); |
|
|
|
notNull(jsonFile, "json file can not be null"); |
|
|
|
isTrue(jsonFile.exists(), "json file does not exist"); |
|
|
|
isTrue(jsonFile.exists(), "json file does not exist"); |
|
|
|
|
|
|
|
notNull(configuration, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
|
|
|
|
FileInputStream fis = null; |
|
|
|
FileInputStream fis = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
fis = new FileInputStream(jsonFile); |
|
|
|
fis = new FileInputStream(jsonFile); |
|
|
|
return read(jsonProvider, jsonProvider.parse(fis)); |
|
|
|
return read(configuration.getProvider().parse(fis), configuration); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
IOUtils.closeQuietly(fis); |
|
|
|
IOUtils.closeQuietly(fis); |
|
|
|
} |
|
|
|
} |
|
|
@ -391,19 +392,19 @@ public class JsonPath { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Applies this JsonPath to the provided json input stream |
|
|
|
* Applies this JsonPath to the provided json input stream |
|
|
|
* |
|
|
|
* |
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
|
|
|
|
* @param jsonInputStream input stream to read from |
|
|
|
* @param jsonInputStream input stream to read from |
|
|
|
|
|
|
|
* @param configuration configuration to use |
|
|
|
* @param <T> expected return type |
|
|
|
* @param <T> expected return type |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @throws IOException |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public <T> T read(JsonProvider jsonProvider, InputStream jsonInputStream) throws IOException { |
|
|
|
public <T> T read(InputStream jsonInputStream, Configuration configuration) throws IOException { |
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notNull(jsonInputStream, "json input stream can not be null"); |
|
|
|
notNull(jsonInputStream, "json input stream can not be null"); |
|
|
|
|
|
|
|
notNull(configuration, "configuration can not be null"); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
return read(jsonProvider, jsonProvider.parse(jsonInputStream)); |
|
|
|
return read(configuration.getProvider().parse(jsonInputStream), configuration); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
IOUtils.closeQuietly(jsonInputStream); |
|
|
|
IOUtils.closeQuietly(jsonInputStream); |
|
|
|
} |
|
|
|
} |
|
|
@ -436,73 +437,34 @@ public class JsonPath { |
|
|
|
// --------------------------------------------------------
|
|
|
|
// --------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a new JsonPath and applies it to the provided Json string |
|
|
|
* Creates a new JsonPath and applies it to the provided Json object |
|
|
|
* |
|
|
|
* |
|
|
|
* @param json a json string |
|
|
|
* @param json a json object |
|
|
|
* @param jsonPath the json path |
|
|
|
* @param jsonPath the json path |
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
* @param <T> expected return type |
|
|
|
* @param <T> expected return type |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @return list of objects matched by the given path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public static <T> T read(String json, String jsonPath, Filter... filters) { |
|
|
|
public static <T> T read(Object json, String jsonPath, Filter... filters) { |
|
|
|
return read(JsonProviderFactory.createProvider(), json, jsonPath, filters); |
|
|
|
return compile(jsonPath, filters).read(json); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a new JsonPath and applies it to the provided Json string |
|
|
|
* Creates a new JsonPath and applies it to the provided Json string |
|
|
|
* |
|
|
|
* |
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
* @param json a json string |
|
|
|
* @param json a json string |
|
|
|
|
|
|
|
* @param jsonPath the json path |
|
|
|
|
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
|
|
|
|
* @param <T> expected return type |
|
|
|
|
|
|
|
* @return list of objects matched by the given path |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
|
|
|
|
public static <T> T read(JsonProvider jsonProvider, String json, String jsonPath, Filter... filters) { |
|
|
|
|
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notEmpty(json, "json can not be null or empty"); |
|
|
|
|
|
|
|
notEmpty(jsonPath, "jsonPath can not be null or empty"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return compile(jsonPath, filters).read(jsonProvider, json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a new JsonPath and applies it to the provided Json object |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param json a json object |
|
|
|
|
|
|
|
* @param jsonPath the json path |
|
|
|
* @param jsonPath the json path |
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
* @param <T> expected return type |
|
|
|
* @param <T> expected return type |
|
|
|
* @return list of objects matched by the given path |
|
|
|
* @return list of objects matched by the given path |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public static <T> T read(Object json, String jsonPath, Filter... filters) { |
|
|
|
public static <T> T read(String json, String jsonPath, Filter... filters) { |
|
|
|
return read(JsonProviderFactory.createProvider(), json, jsonPath, filters); |
|
|
|
return new JsonReader().parse(json).read(jsonPath, filters); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a new JsonPath and applies it to the provided Json object |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
|
|
|
|
* @param json a json object |
|
|
|
|
|
|
|
* @param jsonPath the json path |
|
|
|
|
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
|
|
|
|
* @param <T> expected return type |
|
|
|
|
|
|
|
* @return list of objects matched by the given path |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
|
|
|
|
public static <T> T read(JsonProvider jsonProvider, Object json, String jsonPath, Filter... filters) { |
|
|
|
|
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notNull(json, "json can not be null"); |
|
|
|
|
|
|
|
notNull(jsonPath, "jsonPath can not be null"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return compile(jsonPath, filters).read(jsonProvider, json); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a new JsonPath and applies it to the provided Json object |
|
|
|
* Creates a new JsonPath and applies it to the provided Json object |
|
|
|
* |
|
|
|
* |
|
|
@ -514,26 +476,7 @@ public class JsonPath { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public static <T> T read(URL jsonURL, String jsonPath, Filter... filters) throws IOException { |
|
|
|
public static <T> T read(URL jsonURL, String jsonPath, Filter... filters) throws IOException { |
|
|
|
return read(JsonProviderFactory.createProvider(), jsonURL, jsonPath, filters); |
|
|
|
return new JsonReader().parse(jsonURL).read(jsonPath, filters); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a new JsonPath and applies it to the provided Json object |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
|
|
|
|
* @param jsonURL url pointing to json doc |
|
|
|
|
|
|
|
* @param jsonPath the json path |
|
|
|
|
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
|
|
|
|
* @param <T> expected return type |
|
|
|
|
|
|
|
* @return list of objects matched by the given path |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
|
|
|
|
public static <T> T read(JsonProvider jsonProvider, URL jsonURL, String jsonPath, Filter... filters) throws IOException { |
|
|
|
|
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notNull(jsonURL, "json URL can not be null"); |
|
|
|
|
|
|
|
notEmpty(jsonPath, "jsonPath can not be null or empty"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return compile(jsonPath, filters).read(jsonProvider, jsonURL); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -547,26 +490,7 @@ public class JsonPath { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public static <T> T read(File jsonFile, String jsonPath, Filter... filters) throws IOException { |
|
|
|
public static <T> T read(File jsonFile, String jsonPath, Filter... filters) throws IOException { |
|
|
|
return read(JsonProviderFactory.createProvider(), jsonFile, jsonPath, filters); |
|
|
|
return new JsonReader().parse(jsonFile).read(jsonPath, filters); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a new JsonPath and applies it to the provided Json object |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
|
|
|
|
* @param jsonFile json file |
|
|
|
|
|
|
|
* @param jsonPath the json path |
|
|
|
|
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
|
|
|
|
* @param <T> expected return type |
|
|
|
|
|
|
|
* @return list of objects matched by the given path |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
|
|
|
|
public static <T> T read(JsonProvider jsonProvider, File jsonFile, String jsonPath, Filter... filters) throws IOException { |
|
|
|
|
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
|
|
|
|
notNull(jsonFile, "json file can not be null"); |
|
|
|
|
|
|
|
notEmpty(jsonPath, "jsonPath can not be null or empty"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return compile(jsonPath, filters).read(jsonProvider, jsonFile); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -580,26 +504,60 @@ public class JsonPath { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public static <T> T read(InputStream jsonInputStream, String jsonPath, Filter... filters) throws IOException { |
|
|
|
public static <T> T read(InputStream jsonInputStream, String jsonPath, Filter... filters) throws IOException { |
|
|
|
return read(JsonProviderFactory.createProvider(), jsonInputStream, jsonPath, filters); |
|
|
|
return new JsonReader().parse(jsonInputStream).read(jsonPath, filters); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a new JsonPath and applies it to the provided Json object |
|
|
|
//-------
|
|
|
|
* |
|
|
|
public static ParseContext using(Configuration configuration){ |
|
|
|
* @param jsonProvider JsonProvider to use |
|
|
|
return new JsonReader(configuration); |
|
|
|
* @param jsonInputStream json input stream |
|
|
|
} |
|
|
|
* @param jsonPath the json path |
|
|
|
|
|
|
|
* @param filters filters to be applied to the filter place holders [?] in the path |
|
|
|
public static ParseContext using(JsonProvider provider){ |
|
|
|
* @param <T> expected return type |
|
|
|
return new JsonReader(Configuration.builder().jsonProvider(provider).build()); |
|
|
|
* @return list of objects matched by the given path |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public static ReadContext parse(Object json, Configuration configuration) { |
|
|
|
|
|
|
|
return new JsonReader(configuration).parse(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ReadContext parse(Object json) { |
|
|
|
|
|
|
|
return new JsonReader().parse(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ReadContext parse(String json, Configuration configuration){ |
|
|
|
|
|
|
|
return new JsonReader(configuration).parse(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ReadContext parse(String json) { |
|
|
|
|
|
|
|
return new JsonReader().parse(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ReadContext parse(InputStream json, Configuration configuration) { |
|
|
|
|
|
|
|
return new JsonReader(configuration).parse(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ReadContext parse(InputStream json) { |
|
|
|
|
|
|
|
return new JsonReader().parse(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ReadContext parse(File json, Configuration configuration) throws IOException { |
|
|
|
|
|
|
|
return new JsonReader(configuration).parse(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ReadContext parse(File json) throws IOException { |
|
|
|
|
|
|
|
return new JsonReader().parse(json); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
public static <T> T read(JsonProvider jsonProvider, InputStream jsonInputStream, String jsonPath, Filter... filters) throws IOException { |
|
|
|
public static <T> T read(Configuration configuration, Object json, String path, Filter... filters){ |
|
|
|
notNull(jsonProvider, "jsonProvider can not be null"); |
|
|
|
return compile(path, filters).read(json, configuration); |
|
|
|
notNull(jsonInputStream, "json input stream can not be null"); |
|
|
|
} |
|
|
|
notEmpty(jsonPath, "jsonPath can not be null or empty"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return compile(jsonPath, filters).read(jsonProvider, jsonInputStream); |
|
|
|
@SuppressWarnings({"unchecked"}) |
|
|
|
|
|
|
|
public static <T> T read(Configuration configuration, String json, String path, Filter... filters){ |
|
|
|
|
|
|
|
return read(configuration, configuration.getProvider().parse(json), path, filters); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|