com.fasterxml.jackson.databind.node.ArrayNode#set ( )源码实例Demo

下面列出了com.fasterxml.jackson.databind.node.ArrayNode#set ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openapi-generator   文件: JsonCacheImpl.java
@Override
public JsonCache set(JsonPointer ptr, Object value) {
    String property = ptr.last().getMatchingProperty();
    ContainerNode<?> container = ensureContainerExists(ptr);
    JsonNode node = nodeFor(value);
    switch (container.getNodeType()) {
        case ARRAY:
            ArrayNode array = (ArrayNode) container;
            int index = Integer.parseInt(property);
            if (index < array.size()) {
                array.set(index, node);
            } else {
                // Fill any gap between current size and index with nulls (Jackson doesn't support sparse arrays).
                for (int i = array.size(); i < index; i++)
                    array.add(array.nullNode());
                array.add(node);
            }
            break;
        case OBJECT:
            ((ObjectNode) container).set(property, node);
            break;
        default:
            throw new IllegalArgumentException(ptr + " does not identify a settable container");
    }
    setDirty();
    return this;
}
 
源代码2 项目: flowable-engine   文件: JsonNodeELResolver.java
protected void setValue(ELContext context, ArrayNode node, Object property, Object value) {
    if (readOnly) {
        throw new PropertyNotWritableException("resolver is read-only");
    }

    int index = toIndex(property);
    JsonNode jsonNode = createNode(node, value);
    node.set(index, jsonNode);
    context.setPropertyResolved(true);
}
 
源代码3 项目: knox   文件: JsonFilterReader.java
private void processValueString() throws IOException {
  Level child;
  Level parent;
  String value = null;
  if(stack.isEmpty()) {
    generator.writeString( parser.getText() );
    return;
  }
  parent = stack.peek();
  if( parent.isArray() ) {
    ArrayNode array = (ArrayNode)parent.node;
    array.add( parser.getText() );
    if( bufferingLevel == null ) {
      value = filterStreamValue( parent );
      array.set( array.size()-1, new TextNode( value ) );
    } else {
      array.removeAll();
    }
  } else {
    child = stack.pop();
    parent = stack.peek();
    ((ObjectNode)parent.node ).put( child.field, parser.getText() );
    if( bufferingLevel == null ) {
      child.node = parent.node; // Populate the JsonNode of the child for filtering.
      value = filterStreamValue( child );
    }
  }
  if( bufferingLevel == null ) {
    if( parent.node.isArray() ) {
      ((ArrayNode)parent.node).removeAll();
    } else {
      ((ObjectNode)parent.node).removeAll();
    }
    generator.writeString( value );
  }
}
 
源代码4 项目: keycloak   文件: ReflectionUtil.java
private static void setArrayItem(ArrayNode list, int index, JsonNode valNode) {
    if (index == -1) {
        // append to end of array
        list.add(valNode);
        return;
    }
    // make sure items up to index exist
    for (int i = list.size(); i < index+1; i++) {
        list.add(NullNode.instance);
    }
    list.set(index, valNode);
}