com.jayway.jsonpath.spi.json.JsonProvider.getMapValue()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(120)

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

JsonProvider.getMapValue介绍

[英]Extracts a value from an map
[中]从映射中提取值

代码示例

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

private static Object readObjectProperty(String property, Object model, EvaluationContextImpl ctx) {
  return ctx.jsonProvider().getMapValue(model, property);
}

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

@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

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 boolean apply(PredicateContext ctx) {
    if (ctx.configuration().jsonProvider().getMapValue(ctx.item(), "name").equals("rootGrandChild_A")) {
      return true;
    }
    return false;
  }
};

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

protected void renameInMap(Object targetMap, String oldKeyName, String newKeyName, Configuration configuration){
  if(configuration.jsonProvider().isMap(targetMap)){
    if(configuration.jsonProvider().getMapValue(targetMap, oldKeyName) == JsonProvider.UNDEFINED){
      throw new PathNotFoundException("No results for Key "+oldKeyName+" found in map!");
    }
    configuration.jsonProvider().setProperty(targetMap, newKeyName, configuration.jsonProvider().getMapValue(targetMap, oldKeyName));
    configuration.jsonProvider().removeProperty(targetMap, oldKeyName);
  } else {
    throw new InvalidModificationException("Can only rename properties in 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

public static void walkObject(PathToken pt, String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx, Predicate predicate) {
  if (predicate.matches(model)) {
    pt.evaluate(currentPath, parent, model, ctx);
  }
  Collection<String> properties = ctx.jsonProvider().getPropertyKeys(model);
  for (String property : properties) {
    String evalPath = currentPath + "['" + property + "']";
    Object propertyModel = ctx.jsonProvider().getMapValue(model, property);
    if (propertyModel != JsonProvider.UNDEFINED) {
      walk(pt, evalPath, PathRef.create(model, property), propertyModel, ctx, predicate);
    }
  }
}

代码示例来源: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: com.jayway.jsonpath/json-path

private static Object readObjectProperty(String property, Object model, EvaluationContextImpl ctx) {
  return ctx.jsonProvider().getMapValue(model, property);
}

代码示例来源:origin: com.jayway.jsonpath/json-path

@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: com.jayway.jsonpath/json-path

@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: com.jayway.jsonpath/json-path

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

代码示例来源:origin: com.jayway.jsonpath/json-path

protected void renameInMap(Object targetMap, String oldKeyName, String newKeyName, Configuration configuration){
  if(configuration.jsonProvider().isMap(targetMap)){
    if(configuration.jsonProvider().getMapValue(targetMap, oldKeyName) == JsonProvider.UNDEFINED){
      throw new PathNotFoundException("No results for Key "+oldKeyName+" found in map!");
    }
    configuration.jsonProvider().setProperty(targetMap, newKeyName, configuration.jsonProvider().getMapValue(targetMap, oldKeyName));
    configuration.jsonProvider().removeProperty(targetMap, oldKeyName);
  } else {
    throw new InvalidModificationException("Can only rename properties in a map");
  }
}

代码示例来源:origin: com.jayway.jsonpath/json-path

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: com.jayway.jsonpath/json-path

public static void walkObject(PathToken pt, String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx, Predicate predicate) {
  if (predicate.matches(model)) {
    pt.evaluate(currentPath, parent, model, ctx);
  }
  Collection<String> properties = ctx.jsonProvider().getPropertyKeys(model);
  for (String property : properties) {
    String evalPath = currentPath + "['" + property + "']";
    Object propertyModel = ctx.jsonProvider().getMapValue(model, property);
    if (propertyModel != JsonProvider.UNDEFINED) {
      walk(pt, evalPath, PathRef.create(model, property), propertyModel, ctx, predicate);
    }
  }
}

代码示例来源:origin: com.jayway.jsonpath/json-path

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: com.github.lafa.jsonpath/json-path

@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: com.github.lafa.jsonpath/json-path

protected void renameInMap(Object targetMap, String oldKeyName, String newKeyName, Configuration configuration){
  if(configuration.jsonProvider().isMap(targetMap)){
    if(configuration.jsonProvider().getMapValue(targetMap, oldKeyName) == JsonProvider.UNDEFINED){
      throw new PathNotFoundException("No results for Key "+oldKeyName+" found in map!");
    }
    configuration.jsonProvider().setProperty(targetMap, newKeyName, configuration.jsonProvider().getMapValue(targetMap, oldKeyName));
    configuration.jsonProvider().removeProperty(targetMap, oldKeyName);
  } else {
    throw new InvalidModificationException("Can only rename properties in a map");
  }
}

代码示例来源:origin: com.github.lafa.jsonpath/json-path

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");
  }
}

相关文章