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

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

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

JsonProvider.getArrayIndex介绍

[英]Extracts a value from an array anw unwraps provider specific data type
[中]从数组中提取值并展开特定于提供程序的数据类型

代码示例

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

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

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

public void convert(MapFunction mapFunction, Configuration configuration){
  Object currentValue = configuration.jsonProvider().getArrayIndex(parent, index);
  configuration.jsonProvider().setArrayIndex(parent, index, mapFunction.map(currentValue, configuration));
}

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

@SuppressWarnings("unchecked")
@Override
public <T> T getValue(boolean unwrap) {
  if (path.isDefinite()) {
    if(resultIndex == 0){
      throw new PathNotFoundException("No results for path: " + path.toString());
    }
    int len = jsonProvider().length(valueResult);
    Object value = (len > 0) ? jsonProvider().getArrayIndex(valueResult, len-1) : null;
    if (value != null && unwrap){
     value = jsonProvider().unwrap(value);
    }
    return (T) value;
  }
  return (T)valueResult;
}

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

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

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

protected void handleArrayIndex(int index, String currentPath, Object model, EvaluationContextImpl ctx) {
  String evalPath = Utils.concat(currentPath, "[", String.valueOf(index), "]");
  PathRef pathRef = ctx.forUpdate() ? PathRef.create(model, index) : PathRef.NO_OP;
  int effectiveIndex = index < 0 ? ctx.jsonProvider().length(model) + index : index;
  try {
    Object evalHit = ctx.jsonProvider().getArrayIndex(model, effectiveIndex);
    if (isLeaf()) {
      ctx.addResult(evalPath, pathRef, evalHit);
    } else {
      next().evaluate(evalPath, pathRef, evalHit, ctx);
    }
  } catch (IndexOutOfBoundsException e) {
  }
}

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

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

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

public void convert(MapFunction mapFunction, Configuration configuration){
  Object currentValue = configuration.jsonProvider().getArrayIndex(parent, index);
  configuration.jsonProvider().setArrayIndex(parent, index, mapFunction.map(currentValue, configuration));
}

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

@SuppressWarnings("unchecked")
@Override
public <T> T getValue(boolean unwrap) {
  if (path.isDefinite()) {
    if(resultIndex == 0){
      throw new PathNotFoundException("No results for path: " + path.toString());
    }
    int len = jsonProvider().length(valueResult);
    Object value = (len > 0) ? jsonProvider().getArrayIndex(valueResult, len-1) : null;
    if (value != null && unwrap){
     value = jsonProvider().unwrap(value);
    }
    return (T) value;
  }
  return (T)valueResult;
}

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

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

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

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

protected void handleArrayIndex(int index, String currentPath, Object model, EvaluationContextImpl ctx) {
  String evalPath = Utils.concat(currentPath, "[", String.valueOf(index), "]");
  PathRef pathRef = ctx.forUpdate() ? PathRef.create(model, index) : PathRef.NO_OP;
  int effectiveIndex = index < 0 ? ctx.jsonProvider().length(model) + index : index;
  try {
    Object evalHit = ctx.jsonProvider().getArrayIndex(model, effectiveIndex);
    if (isLeaf()) {
      ctx.addResult(evalPath, pathRef, evalHit);
    } else {
      next().evaluate(evalPath, pathRef, evalHit, ctx);
    }
  } catch (IndexOutOfBoundsException e) {
  }
}

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

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

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

public void convert(MapFunction mapFunction, Configuration configuration){
  Object currentValue = configuration.jsonProvider().getArrayIndex(parent, index);
  configuration.jsonProvider().setArrayIndex(parent, index, mapFunction.map(currentValue, configuration));
}

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

@SuppressWarnings("unchecked")
@Override
public <T> T getValue(boolean unwrap) {
  if (path.isDefinite()) {
    if(resultIndex == 0){
      throw new PathNotFoundException("No results for path: " + path.toString());
    }
    int len = jsonProvider().length(valueResult);
    Object value = (len > 0) ? jsonProvider().getArrayIndex(valueResult, len-1) : null;
    if (value != null && unwrap){
     value = jsonProvider().unwrap(value);
    }
    return (T) value;
  }
  return (T)valueResult;
}

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

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

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

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

int effectiveIndex = index < 0 ? ctx.jsonProvider().length(model) + index : index;
try {
  Object evalHit = ctx.jsonProvider().getArrayIndex(model, effectiveIndex);
  if (isLeaf()) {
    if (ctx.configuration().getComputeRoot()) {
      curr = (ctx.configuration().jsonProvider().length(old) > effectiveIndex
          ? ctx.configuration().jsonProvider().getArrayIndex(old, effectiveIndex) : null);
      if (null == curr) {
        curr = ctx.configuration().jsonProvider().createMap();

相关文章