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

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

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

Configuration.builder介绍

[英]Returns a new ConfigurationBuilder
[中]返回新的ConfigurationBuilder

代码示例

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

/**
 * Creates a {@link ParseContext} that will parse a given JSON input.
 *
 * @param provider jsonProvider to use when parsing JSON
 * @return a parsing context based on given jsonProvider
 */
@Deprecated
public static ParseContext using(JsonProvider provider) {
  return new ParseContextImpl(Configuration.builder().jsonProvider(provider).build());
}

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

ParquetGroupFlattenerMaker(boolean binaryAsString)
{
 this.converter = new ParquetGroupConverter(binaryAsString);
 this.jsonPathConfiguration = Configuration.builder()
                      .jsonProvider(new ParquetGroupJsonProvider(converter))
                      .mappingProvider(new NotImplementedMappingProvider())
                      .options(EnumSet.of(Option.SUPPRESS_EXCEPTIONS))
                      .build();
}

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

/**
 * Creates a new Configuration by the provided evaluation listeners to the current listeners
 * @param evaluationListener listeners
 * @return a new configuration
 */
public Configuration addEvaluationListeners(EvaluationListener... evaluationListener){
  return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListener).build();
}

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

/**
 * Creates a new configuration with the provided options. Options in this configuration are discarded.
 * @param options
 * @return
 */
public Configuration setOptions(Option... options) {
  return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListeners).build();
}

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

/**
 * Creates a new Configuration based on the given {@link com.jayway.jsonpath.spi.json.JsonProvider}
 * @param newJsonProvider json provider to use in new configuration
 * @return a new configuration
 */
public Configuration jsonProvider(JsonProvider newJsonProvider) {
  return Configuration.builder().jsonProvider(newJsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListeners).build();
}

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

/**
 * Creates a new Configuration based on the given {@link com.jayway.jsonpath.spi.mapper.MappingProvider}
 * @param newMappingProvider mapping provider to use in new configuration
 * @return a new configuration
 */
public Configuration mappingProvider(MappingProvider newMappingProvider) {
  return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(newMappingProvider).options(options).evaluationListener(evaluationListeners).build();
}

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

/**
 * Creates a new Configuration with the provided evaluation listeners
 * @param evaluationListener listeners
 * @return a new configuration
 */
public Configuration setEvaluationListeners(EvaluationListener... evaluationListener){
  return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListener).build();
}

代码示例来源: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_22c() throws Exception {
  //Configuration configuration = Configuration.builder().build();
  Configuration configuration = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
  String json = "{\"a\":{\"b\":1,\"c\":2}}";
  assertNull(JsonPath.parse(json, configuration).read("a.d"));
}

代码示例来源: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
public void property_not_found() {
  //String result = JsonPath.read(SIMPLE_MAP, "$.not-found");
  //assertThat(result).isNull();
  Configuration configuration = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
  String json = "{\"a\":{\"b\":1,\"c\":2}}";
  assertNull(JsonPath.parse(SIMPLE_MAP, configuration).read("$.not-found"));
}

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

@Test
public void an_evaluation_listener_can_abort_after_one_result_using_configuration() {
  EvaluationListener firstResultListener = new EvaluationListener() {
    @Override
    public EvaluationContinuation resultFound(FoundResult found) {
      return EvaluationContinuation.ABORT;
    }
  };
  Configuration configuration = Configuration.builder().evaluationListener(firstResultListener).build();
  List<String> title = JsonPath.using(configuration).parse(JSON_DOCUMENT).read("$..title", List.class);
  assertThat(title).containsExactly("Sayings of the Century");
}

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

@Test
public void a_leafs_can_be_defaulted_to_null() {
  Configuration conf = Configuration.builder().options(DEFAULT_PATH_LEAF_TO_NULL).build();
  assertThat(using(conf).parse("{\"foo\" : \"bar\"}").read("$.baz", Object.class)).isNull();
}

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

@Test
public void a_path_evaluation_can_be_returned_as_PATH_LIST() {
  Configuration conf = Configuration.builder().options(AS_PATH_LIST).build();
  List<String> pathList = using(conf).parse(JSON_DOCUMENT).read("$..author");
  assertThat(pathList).containsExactly(
      "$['store']['book'][0]['author']",
      "$['store']['book'][1]['author']",
      "$['store']['book'][2]['author']",
      "$['store']['book'][3]['author']");
}

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

@Test
public void a_path_evaluation_can_be_returned_as_PATH_LIST() {
  Configuration conf = Configuration.builder().options(AS_PATH_LIST).build();
  List<String> pathList = using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo");
  assertThat(pathList).containsOnly("$['foo']");
}

代码示例来源: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 a_definite_path_can_be_returned_as_list() {
  Configuration conf = Configuration.builder().options(ALWAYS_RETURN_LIST).build();
  assertThat((List)using(conf).parse("{\"foo\" : \"bar\"}").read("$.foo")).isInstanceOf(List.class);
  assertThat((List)using(conf).parse("{\"foo\": null}").read("$.foo")).isInstanceOf(List.class);
  assertThat((List)using(conf).parse("{\"foo\": [1, 4, 8]}").read("$.foo")).asList()
      .containsExactly(Arrays.asList(1, 4, 8));
}

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

@Test
public void issue_suppress_exceptions_does_not_break_indefinite_evaluation() {
  Configuration conf = Configuration.builder().options(SUPPRESS_EXCEPTIONS).build();
  assertThat((List)using(conf).parse("{\"foo2\": [5]}").read("$..foo2[0]")).asList().containsOnly(5);
  assertThat((List)using(conf).parse("{\"foo\" : {\"foo2\": [5]}}").read("$..foo2[0]")).asList().containsOnly(5);
  assertThat((List)using(conf).parse("[null, [{\"foo\" : {\"foo2\": [5]}}]]").read("$..foo2[0]")).asList().containsOnly(5);
  assertThat((List)using(conf).parse("[null, [{\"foo\" : {\"foo2\": [5]}}]]").read("$..foo.foo2[0]")).asList().containsOnly(5);
  assertThat((List)using(conf).parse("{\"aoo\" : {}, \"foo\" : {\"foo2\": [5]}, \"zoo\" : {}}").read("$[*].foo2[0]")).asList().containsOnly(5);
}

相关文章