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

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

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

Configuration.jsonProvider介绍

[英]Returns com.jayway.jsonpath.spi.json.JsonProvider used by this configuration
[中]返回com。乱穿马路。jsonpath。spi。json。此配置使用的JsonProvider

代码示例

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

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

public void delete(Configuration configuration){
  for (String property : properties) {
    configuration.jsonProvider().removeProperty(parent, property);
  }
}

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

@Override
public List<String> getPathList() {
  List<String> res = new ArrayList<String>();
  if(resultIndex > 0){
    Iterable<?> objects = configuration.jsonProvider().toIterable(pathResult);
    for (Object o : objects) {
      res.add((String)o);
    }
  }
  return res;
}

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

@Override
public void add(Object newVal, Configuration configuration) {
  if(configuration.jsonProvider().isArray(parent)){
    configuration.jsonProvider().setArrayIndex(parent, configuration.jsonProvider().length(parent), newVal);
  } else {
    throw new InvalidModificationException("Invalid add operation. $ is not an array");
  }
}

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

public void add(Object value, Configuration configuration){
  Object target = configuration.jsonProvider().getMapValue(parent, property);
  if(targetInvalid(target)){
    return;
  }
  if(configuration.jsonProvider().isArray(target)){
    configuration.jsonProvider().setArrayIndex(target, configuration.jsonProvider().length(target), value);
  } else {
    throw new InvalidModificationException("Can only add to an array");
  }
}

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

public void convert(MapFunction mapFunction, Configuration configuration) {
  for (String property : properties) {
    Object currentValue = configuration.jsonProvider().getMapValue(parent, property);
    if (currentValue != JsonProvider.UNDEFINED) {
      configuration.jsonProvider().setProperty(parent, property, mapFunction.map(currentValue, configuration));
    }
  }
}

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

@Override
public void convert(MapFunction mapFunction, Configuration configuration) {
  Object currentValue = configuration.jsonProvider().getMapValue(parent, property);
  configuration.jsonProvider().setProperty(parent, property, mapFunction.map(currentValue, configuration));
}

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

@Override
public void put(String key, Object newVal, Configuration configuration) {
  if(configuration.jsonProvider().isMap(parent)){
    configuration.jsonProvider().setProperty(parent, key, newVal);
  } else {
    throw new InvalidModificationException("Invalid put operation. $ is not a map");
  }
}

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

public void put(String key, Object value, Configuration configuration){
  Object target = configuration.jsonProvider().getArrayIndex(parent, index);
  if(targetInvalid(target)){
    return;
  }
  if(configuration.jsonProvider().isMap(target)){
    configuration.jsonProvider().setProperty(target, key, value);
  } else {
    throw new InvalidModificationException("Can only add properties to a map");
  }
}

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

public void put(String key, Object value, Configuration configuration){
  Object target = configuration.jsonProvider().getMapValue(parent, property);
  if(targetInvalid(target)){
    return;
  }
  if(configuration.jsonProvider().isMap(target)){
    configuration.jsonProvider().setProperty(target, key, value);
  } else {
    throw new InvalidModificationException("Can only add properties to a map");
  }
}

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

@Override
  public Object invoke(String currentPath, PathRef parent, Object model, EvaluationContext ctx, List<Parameter> parameters) {
    if(ctx.configuration().jsonProvider().isArray(model)){
      return ctx.configuration().jsonProvider().length(model);
    } else if(ctx.configuration().jsonProvider().isMap(model)){
      return ctx.configuration().jsonProvider().length(model);
    }
    return null;
  }
}

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

@Override
public DocumentContext parse(String json) {
  notEmpty(json, "json string can not be null or empty");
  Object obj = configuration.jsonProvider().parse(json);
  return new JsonContext(obj, configuration);
}

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

@Override
public void renameKey(String oldKeyName, String newKeyName, Configuration configuration) {
  Object target = configuration.jsonProvider().getMapValue(parent, property);
  if(targetInvalid(target)){
    return;
  }
  renameInMap(target, oldKeyName, newKeyName, configuration);
}

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

@Test
public void escaped_literals() {
  if(conf.jsonProvider().getClass().getSimpleName().startsWith("Jackson")){
    return;
  }
  assertHasOneResult("[\"\\'foo\"]", "$[?(@ == '\\'foo')]", conf);
}

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

@Override
public DocumentContext parse(InputStream json, String charset) {
  notNull(json, "json input stream can not be null");
  notNull(charset, "charset can not be null");
  try {
    Object obj = configuration.jsonProvider().parse(json, charset);
    return new JsonContext(obj, configuration);
  } finally {
    Utils.closeQuietly(json);
  }
}

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

@Override
  public boolean apply(PredicateContext ctx) {
    if (ctx.configuration().jsonProvider().getMapValue(ctx.item(), "name").equals("rootGrandChild_A")) {
      return true;
    }
    return false;
  }
};

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

/**
   * Shortcut for counting found nodes.
   * @param json json to be parsed
   * @param path path to be evaluated
   * @param expectedResultCount expected number of nodes to be found
   * @param conf conf to use during evaluation
   */
  public static void assertHasResults(final String json, final String path, final int expectedResultCount, Configuration conf) {
    Object result = JsonPath.using(conf).parse(json).read(path);
    assertThat(conf.jsonProvider().length(result)).isEqualTo(expectedResultCount);
  }
}

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

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

代码示例来源: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 filters_can_contain_json_path_expressions() throws Exception {
  Object doc = Configuration.defaultConfiguration().jsonProvider().parse(DOCUMENT);
  assertFalse(filter(where("$.store.bicycle.color").ne("red")).apply(createPredicateContext(doc)));
}

相关文章