本文整理汇总了Java中com.jayway.jsonpath.JsonPath.compile方法的典型用法代码示例。如果您正苦于以下问题:Java JsonPath.compile方法的具体用法?Java JsonPath.compile怎么用?Java JsonPath.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jayway.jsonpath.JsonPath
的用法示例。
在下文中一共展示了JsonPath.compile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepPath
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
/**
* Assemble an xpath using the given json path and json wrapper.
*
* @param jsonPath definite json path
* @param wrapper object representation of QPP json
* @return xpath that correlates to supplied json path
*/
public static String prepPath(String jsonPath, JsonWrapper wrapper) {
String base = "$";
String leaf = jsonPath;
int lastIndex = jsonPath.lastIndexOf('.');
JsonWrapper metaWrapper = new JsonWrapper(wrapper, false);
if (lastIndex > 0) {
base = jsonPath.substring(0, lastIndex);
leaf = jsonPath.substring(lastIndex + 1);
}
JsonPath compiledPath = JsonPath.compile(base);
Map<String, Object> jsonMap = compiledPath.read(metaWrapper.toString());
Map<String, String> metaMap = getMetaMap(jsonMap, leaf);
String preparedPath = "";
if (metaMap != null) {
preparedPath = makePath(metaMap, leaf);
}
return preparedPath;
}
示例2: assertIsValidJsonPath
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
/**
* Asserts that the string represents a valid JsonPath expression.
*
* @param path Path expression to validate.
* @param propertyName Name of property.
*/
public void assertIsValidJsonPath(String path, String propertyName) {
if (path == null) {
return;
}
if (path.isEmpty()) {
problemReporter.report(new Problem(this, String.format("%s cannot be empty", propertyName)));
return;
}
try {
JsonPath.compile(path);
} catch (InvalidPathException e) {
problemReporter.report(new Problem(this,
String.format("%s with value '%s' is not a valid JsonPath. %s", propertyName, path,
e.getMessage())));
}
}
示例3: EnsureSimplePatternCompiles
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
@Test
public void EnsureSimplePatternCompiles() throws Exception {
final JsonPath pattern = JsonPath.compile("$.test");
final Boolean read = pattern.<Boolean>read("{\"test\":true}");
then(read).isTrue();
// Investigate classpath problems (CNFE) in runtime
LoggerFactory.getLogger(JsonPathTest.class);
then(Class.forName("com.jayway.jsonpath.internal.path.CompiledPath")).isNotNull();
}
示例4: validateJsonPath
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
private static void validateJsonPath(String expr) {
try {
JsonPath.compile(expr);
} catch (Exception e) {
throw new QueryException("expression syntax error: " + expr, e);
}
}
示例5: body
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public static Object body(String input, String path) {
JsonPath jsonPath = JsonPath.compile(path);
return jsonPath.read(input);
}
示例6: JsonPathSelector
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
public JsonPathSelector(String jsonPathStr) {
this.jsonPathStr = jsonPathStr;
this.jsonPath = JsonPath.compile(this.jsonPathStr);
}
示例7: extractFromJson
import com.jayway.jsonpath.JsonPath; //导入方法依赖的package包/类
/**
*
* @param input
* @param path
* @return
*/
public static Object extractFromJson(String input, String path) {
JsonPath jsonPath = JsonPath.compile(path);
return jsonPath.read(input);
}