com.jayway.jsonpath.Configuration.defaultConfiguration()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中com.jayway.jsonpath.Configuration.defaultConfiguration()方法的一些代码示例,展示了Configuration.defaultConfiguration()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.defaultConfiguration()方法的具体详情如下:
包路径:com.jayway.jsonpath.Configuration
类名称:Configuration
方法名:defaultConfiguration

Configuration.defaultConfiguration介绍

[英]Creates a new configuration based on default values
[中]基于默认值创建新配置

代码示例

代码示例来源: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

/**
 * Applies this JsonPath to the provided json URL
 *
 * @param jsonURL url to read from
 * @param <T>     expected return type
 * @return list of objects matched by the given path
 * @throws IOException
 */
@SuppressWarnings({"unchecked"})
public <T> T read(URL jsonURL) throws IOException {
  return read(jsonURL, Configuration.defaultConfiguration());
}

代码示例来源:origin: json-path/JsonPath

@Override
  public Configuration configuration() {
    return Configuration.defaultConfiguration();
  }
};

代码示例来源:origin: json-path/JsonPath

/**
 * Applies this JsonPath to the provided json input stream
 *
 * @param jsonInputStream input stream to read from
 * @param <T>             expected return type
 * @return list of objects matched by the given path
 * @throws IOException
 */
@SuppressWarnings({"unchecked"})
public <T> T read(InputStream jsonInputStream) throws IOException {
  return read(jsonInputStream, Configuration.defaultConfiguration());
}

代码示例来源:origin: json-path/JsonPath

/**
 * Applies this JsonPath to the provided json file
 *
 * @param jsonFile file to read from
 * @param <T>      expected return type
 * @return list of objects matched by the given path
 * @throws IOException
 */
@SuppressWarnings({"unchecked"})
public <T> T read(File jsonFile) throws IOException {
  return read(jsonFile, Configuration.defaultConfiguration());
}

代码示例来源: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

@Override
public JsonAsserter assertNotDefined(String path, String message) {
  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

@Test
public void a_path_evaluation_is_returned_as_VALUE_by_default() {
  Configuration conf = Configuration.defaultConfiguration();
  assertThat((String)using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isEqualTo("bar");
}

代码示例来源:origin: json-path/JsonPath

@Test
public void when_deep_scanning_require_properties_is_ignored_on_scan_target_but_not_on_children() {
  final Configuration conf = Configuration.defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES);
  assertEvaluationThrows("{\"foo\": {\"baz\": 4}}", "$..foo.bar", PathNotFoundException.class, conf);
}

代码示例来源: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: json-path/JsonPath

@Test
public void path() {
  String json = "{\"a\":[{\"b\":1,\"c\":2},{\"b\":5,\"c\":2}]}";
  List<Object> result = JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.DEFAULT_PATH_LEAF_TO_NULL)).parse(json).read("a[?(@.b==5)].d");
  Assertions.assertThat(result).hasSize(1);
  Assertions.assertThat(result.get(0)).isNull();
}

代码示例来源:origin: json-path/JsonPath

@Test
public void testFilterWithOrShortCircuit2() throws Exception {
  Object json = Configuration.defaultConfiguration().jsonProvider().parse("{\"firstname\":\"Bob\",\"surname\":\"Smith\",\"age\":30}");
  assertThat(Filter.parse("[?((@.firstname == 'Bob' || @.firstname == 'Jane') && @.surname == 'Smith')]").apply(createPredicateContext(json))).isTrue();
}

代码示例来源:origin: json-path/JsonPath

@Test
public void all_store_properties() throws Exception {
  /*
  List<Object> itemsInStore = JsonPath.read(DOCUMENT, "$.store.*");
  assertEquals(JsonPath.read(itemsInStore, "$.[0].[0].author"), "Nigel Rees");
  assertEquals(JsonPath.read(itemsInStore, "$.[0][0].author"), "Nigel Rees");
  */
  List<String> result = PathCompiler.compile("$.store.*").evaluate(OBJ_DOCUMENT, OBJ_DOCUMENT, Configuration.defaultConfiguration()).getPathList();
  Assertions.assertThat(result).containsOnly(
      "$['store']['bicycle']",
      "$['store']['book']");
}

代码示例来源:origin: json-path/JsonPath

@Test(expected = PathNotFoundException.class)
public void property_not_found_option_throw() {
  //String result = JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.THROW_ON_MISSING_PROPERTY)).parse(SIMPLE_MAP).read("$.not-found");
  String result = JsonPath.using(Configuration.defaultConfiguration()).parse(SIMPLE_MAP).read("$.not-found");
  assertThat(result).isNull();
}

代码示例来源:origin: json-path/JsonPath

@Test(expected = PathNotFoundException.class)
public void a_leafs_is_not_defaulted_to_null() {
  Configuration conf = Configuration.defaultConfiguration();
  assertThat((String)using(conf).parse("{\"foo\" : \"bar\"}").read("$.baz")).isNull();
}

代码示例来源:origin: json-path/JsonPath

@Test
public void a_definite_path_is_not_returned_as_list_by_default() {
  Configuration conf = Configuration.defaultConfiguration();
  assertThat((String)using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isInstanceOf(String.class);
}

代码示例来源: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

@Test
public void issue_22b() throws Exception {
  String json = "{\"a\":[{\"b\":1,\"c\":2},{\"b\":5,\"c\":2}]}";
  List<Object> res = JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.DEFAULT_PATH_LEAF_TO_NULL)).parse(json).read("a[?(@.b==5)].d");
  assertThat(res).hasSize(1).containsNull();
}

代码示例来源:origin: json-path/JsonPath

@Test
public void multi_props_can_be_defaulted_to_null() {
  Map<String, Object> model = new HashMap<String, Object>(){{
    put("a", "a-val");
    put("b", "b-val");
    put("c", "c-val");
  }};
  Configuration conf = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
  assertThat(using(conf).parse(model).read("$['a', 'd']", Map.class))
      .containsEntry("a", "a-val")
      .containsEntry("d", null);
}

代码示例来源:origin: json-path/JsonPath

@Test(expected = PathNotFoundException.class)
public void multi_props_can_be_required() {
  Map<String, Object> model = new HashMap<String, Object>(){{
    put("a", "a-val");
    put("b", "b-val");
    put("c", "c-val");
  }};
  Configuration conf = Configuration.defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES);
  using(conf).parse(model).read("$['a', 'x']", Map.class);
}

相关文章