本文整理了Java中com.jayway.jsonpath.Configuration
类的一些代码示例,展示了Configuration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration
类的具体详情如下:
包路径:com.jayway.jsonpath.Configuration
类名称:Configuration
[英]Immutable configuration object
[中]不可变配置对象
代码示例来源:origin: json-path/JsonPath
/**
* Applies this JsonPath to the provided json string
*
* @param json a json string
* @param <T> expected return type
* @return list of objects matched by the given path
*/
@SuppressWarnings({"unchecked"})
public <T> T read(String json) {
return read(json, Configuration.defaultConfiguration());
}
代码示例来源:origin: json-path/JsonPath
/**
* Creates a new configuration by adding the new options to the options used in this configuration.
* @param options options to add
* @return a new configuration
*/
public Configuration addOptions(Option... options) {
EnumSet<Option> opts = EnumSet.noneOf(Option.class);
opts.addAll(this.options);
opts.addAll(asList(options));
return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(opts).evaluationListener(evaluationListeners).build();
}
代码示例来源:origin: apache/geode
private void saveDefaults() {
try {
Configuration defaultConfiguration = Configuration.defaultConfiguration();
this.jsonProvider = defaultConfiguration.jsonProvider();
this.mappingProvider = defaultConfiguration.mappingProvider();
this.options = defaultConfiguration.getOptions();
this.hadDefaults = true;
} catch (NoClassDefFoundError ignore) {
this.hadDefaults = false;
}
}
代码示例来源:origin: pentaho/pentaho-kettle
private Configuration deleteOptionFromConfiguration( Configuration config, Option option ) {
Configuration currentConf = config;
if ( currentConf != null ) {
EnumSet<Option> currentOptions = EnumSet.noneOf( Option.class );
currentOptions.addAll( currentConf.getOptions() );
if ( currentOptions.remove( option ) ) {
if ( log.isDebug() ) {
log.logDebug( BaseMessages.getString( PKG, "JsonReader.Debug.Configuration.Option.Delete", option ) );
}
currentConf = Configuration.defaultConfiguration().addOptions( currentOptions.toArray( new Option[currentOptions.size()] ) );
}
}
if ( log.isDebug() ) {
log.logDebug( BaseMessages.getString( PKG, "JsonReader.Debug.Configuration.Options", currentConf.getOptions() ) );
}
return currentConf;
}
代码示例来源:origin: json-path/JsonPath
/**
* Creates a new configuration based on default values
* @return a new configuration based on defaults
*/
public static Configuration defaultConfiguration() {
Defaults defaults = getEffectiveDefaults();
return Configuration.builder().jsonProvider(defaults.jsonProvider()).options(defaults.options()).build();
}
代码示例来源:origin: json-path/JsonPath
@Test
public void issue_46() {
String json = "{\"a\": {}}";
Configuration configuration = Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS);
assertThat((String)JsonPath.using(configuration).parse(json).read("a.x")).isNull();
try {
read(json, "a.x");
failBecauseExceptionWasNotThrown(PathNotFoundException.class);
} catch (PathNotFoundException e) {
assertThat(e).hasMessage("No results for path: $['a']['x']");
}
}
代码示例来源:origin: json-path/JsonPath
@Test
public void last_token_defaults_to_null() {
Configuration configuration = Configuration.builder().options(Option.DEFAULT_PATH_LEAF_TO_NULL).build();
assertNull(JsonPath.parse(DOCUMENT, configuration).read("$.children[2].age"));
}
代码示例来源:origin: json-path/JsonPath
@Test(expected = PathNotFoundException.class)
public void missing_prop() {
//Object read = JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.THROW_ON_MISSING_PROPERTY)).parse(DOCUMENT).read("$.store.book[*].fooBar");
//Object read = JsonPath.using(Configuration.defaultConfiguration()).parse(DOCUMENT).read("$.store.book[*].fooBar");
Object read2 = JsonPath.using(Configuration.defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES)).parse(DOCUMENT).read("$.store.book[*].fooBar.not");
}
代码示例来源:origin: json-path/JsonPath
@Test
public void when_deep_scanning_require_properties_is_ignored_on_scan_target() {
final Configuration conf = Configuration.defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES);
Object result = JsonPath.parse("[{\"x\": {\"foo\": {\"x\": 4}, \"x\": null}, \"y\": {\"x\": 1}}, {\"x\": []}]").read(
"$..x");
assertThat(result).asList().hasSize(5);
List<Integer> result1 = JsonPath.using(conf).parse("{\"foo\": {\"bar\": 4}}").read("$..foo.bar");
assertThat(result1).containsExactly(4);
assertEvaluationThrows("{\"foo\": {\"baz\": 4}}", "$..foo.bar", PathNotFoundException.class, conf);
}
代码示例来源:origin: json-path/JsonPath
@Test
public void an_indefinite_path_can_be_returned_as_list() {
Configuration conf = Configuration.builder().options(ALWAYS_RETURN_LIST).build();
List<Object> result = using(conf).parse("{\"bar\": {\"foo\": null}}").read("$..foo");
assertThat(result).hasSize(1);
assertThat(result.get(0)).isNull();
assertThat((List)using(conf).parse("{\"bar\": {\"foo\": [1, 4, 8]}}").read("$..foo")).asList()
.containsExactly(Arrays.asList(1, 4, 8));
}
代码示例来源:origin: batfish/batfish
private static Set<JsonPathResultEntry> computeResults(
String jsonFile, String path, boolean includeSuffix) {
Configuration.setDefaults(BatfishJsonPathDefaults.INSTANCE);
ConfigurationBuilder b = new ConfigurationBuilder();
Configuration baseConfiguration = b.build();
String jsonStr = CommonUtil.readResource(jsonFile);
Object jsonObject = JsonPath.parse(jsonStr, baseConfiguration).json();
JsonPathQuery query = new JsonPathQuery(path, includeSuffix);
JsonPathResult result = JsonPathAnswerer.computeResult(jsonObject, query);
return new HashSet<>(result.getResult().values());
}
代码示例来源:origin: batfish/batfish
public JsonPathTest() {
Configuration.setDefaults(BatfishJsonPathDefaults.INSTANCE);
ConfigurationBuilder b = new ConfigurationBuilder();
_baseConfiguration = b.build();
_oneNtpServerNodesAnswerStr =
CommonUtil.readResource("org/batfish/question/jsonpath/oneNtpServer.json");
_oneNtpServerNodesAnswerJsonObject =
JsonPath.parse(_oneNtpServerNodesAnswerStr, _baseConfiguration).json();
_twoNtpServersNodesAnswerStr =
CommonUtil.readResource("org/batfish/question/jsonpath/twoNtpServers.json");
_twoNtpServersNodesAnswerJsonObject =
JsonPath.parse(_twoNtpServersNodesAnswerStr, _baseConfiguration).json();
ConfigurationBuilder prefixCb = new ConfigurationBuilder();
prefixCb.mappingProvider(_baseConfiguration.mappingProvider());
prefixCb.jsonProvider(_baseConfiguration.jsonProvider());
prefixCb.evaluationListener(_baseConfiguration.getEvaluationListeners());
prefixCb.options(_baseConfiguration.getOptions());
prefixCb.options(Option.ALWAYS_RETURN_LIST);
prefixCb.options(Option.AS_PATH_LIST);
_prefixConfiguration = prefixCb.build();
}
代码示例来源:origin: json-path/JsonPath
@Test(expected = PathNotFoundException.class)
public void issue_22() throws Exception {
Configuration configuration = Configuration.defaultConfiguration();
String json = "{\"a\":{\"b\":1,\"c\":2}}";
JsonPath.parse(json, configuration).read("a.d");
}
代码示例来源:origin: org.apache.camel/camel-jsonpath
return path.read(inputStream, genericFile.getCharset(), configuration);
LOG.trace("JSonPath: {} is read as String: {}", path, json);
String str = (String) json;
return path.read(str, configuration);
} else if (json instanceof Map) {
LOG.trace("JSonPath: {} is read as Map: {}", path, json);
Map map = (Map) json;
return path.read(map, configuration);
} else if (json instanceof List) {
LOG.trace("JSonPath: {} is read as List: {}", path, json);
if (configuration.getOptions().contains(SUPPRESS_EXCEPTIONS)) {
if (configuration.getOptions().contains(ALWAYS_RETURN_LIST)) {
return Collections.emptyList();
} else {
代码示例来源:origin: json-path/JsonPath
@Test
public void issue_143() {
String json = "{ \"foo\": { \"bar\" : \"val\" }, \"moo\": { \"cow\" : \"val\" } }";
Configuration configuration = Configuration.builder().options( Option.AS_PATH_LIST ).build();
List<String> pathList = JsonPath.using(configuration).parse(json).read(JsonPath.compile("$.*.bar"));
assertThat(pathList).containsExactly("$['foo']['bar']");
}
代码示例来源:origin: json-path/JsonPath
@Test
public void shouldMatchJsonPathOnParsedJsonObject() {
Object json = Configuration.defaultConfiguration().jsonProvider().parse(BOOKS_JSON);
assertThat(json, hasJsonPath("$.store.name", equalTo("Little Shop")));
}
代码示例来源:origin: json-path/JsonPath
@Test
public void require_single_property() {
List json = new ArrayList() {{
add(singletonMap("a", "a0"));
add(singletonMap("b", "b2"));
}};
Configuration configuration = JSON_SMART_CONFIGURATION.addOptions(Option.REQUIRE_PROPERTIES);
Object result = JsonPath.using(configuration).parse(json).read("$..a");
assertThat(result).asList().containsExactly("a0");
}
代码示例来源:origin: json-path/JsonPath
@Test
public void the_age_of_all_with_age_defined() {
//List<Integer> result = JsonPath.read(DOCUMENT, "$.children[*].age");
List<Integer> result = JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS)).parse(DOCUMENT).read("$.children[*].age");
Assertions.assertThat(result).containsSequence(0, null);
}
代码示例来源:origin: json-path/JsonPath
/**
* {@inheritDoc}
*/
public JsonAsserter assertNotDefined(String path) {
try {
Configuration c = Configuration.defaultConfiguration();
JsonPath.using(c).parse(jsonObject).read(path);
throw new AssertionError(format("Document contains the path <%s> but was expected not to.", path));
} catch (PathNotFoundException e) {
}
return this;
}
代码示例来源:origin: json-path/JsonPath
public void set(Object newVal, Configuration configuration){
for (String property : properties) {
configuration.jsonProvider().setProperty(parent, property, newVal);
}
}
public void convert(MapFunction mapFunction, Configuration configuration) {
内容来源于网络,如有侵权,请联系作者删除!