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

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

源代码1 项目: KaiZen-OpenAPI-Editor   文件: SwaggerSchema.java
public void allowJsonRefInContext(String jsonReferenceContext, boolean allow) {
    if (jsonRefContexts.get(jsonReferenceContext) == null) {
        throw new IllegalArgumentException("Invalid JSON Reference Context: " + jsonReferenceContext);
    }
    // special case
    if (SwaggerPreferenceConstants.VALIDATION_REF_SECURITY_DEFINITIONS_OBJECT.equals(jsonReferenceContext)) {
        allowJsonRefInSecurityDefinitionsObject(allow);
        return;
    }
    ArrayNode definition = (ArrayNode) jsonRefContexts.get(jsonReferenceContext);
    // should preserve order of the original ArrayNode._children
    List<JsonNode> children = new ArrayList<>();
    definition.elements().forEachRemaining(children::add);
    
    int indexOfJsonReference = children.indexOf(refToJsonReferenceNode);
    boolean alreadyHasJsonReference = indexOfJsonReference > -1;
    if (allow) {
        if (!alreadyHasJsonReference) {
            definition.add(refToJsonReferenceNode.deepCopy());
        }
    } else { // disallow
        if (alreadyHasJsonReference) {
            definition.remove(indexOfJsonReference);
        }
    }
}
 
private static void removeNulls(JsonNode tree) {
	if (tree instanceof ArrayNode) {
		ArrayNode array = (ArrayNode) tree;
		for (int i = array.size() - 1; i >= 0; i--) {
			if (array.get(i).isNull()) {
				array.remove(i);
			} else {
				removeNulls(array.get(i));
			}
		}
	} else if (tree instanceof ObjectNode) {
		ObjectNode object = (ObjectNode) tree;
		Set<String> nulls = new HashSet<String>();
		for (Iterator<String> it = object.fieldNames(); it.hasNext();) {
			String name = it.next();
			if (object.get(name).isNull()) {
				nulls.add(name);
			} else {
				removeNulls(object.get(name));
			}
		}
		object.remove(nulls);
	}
}
 
/**
 * Scan the specification and leave only the security method picked by user, if any present.
 * The change is required to avoid exposure of security configuration (such as apikey) through other channels not requested by user,
 * for example, query parameters when the user only wants to provide api key through http headers.
 *
 * @param specification                    the swagger/openapi original specification
 * @param securityDefinitionSelectedByUser the securityDefinition picked by the user
 * @return the updated swagger/openapi specification or the original specification
 */
private static String updateSecuritySpecification(final String specification, final String securityDefinitionSelectedByUser) throws JsonProcessingException {
    final Optional<String> securityDefinitionName = getNameFromDefinition(securityDefinitionSelectedByUser);
    if (securityDefinitionName.isPresent()) {
        JsonNode rootNode = OBJECT_MAPPER.readTree(specification);
        List<JsonNode> securities = rootNode.findValues("security");
        if (!securities.isEmpty()) {
            LOG.info("Updating specification to accept only {} user selected security method", securityDefinitionName.get());
            for (JsonNode endpointSecurity : securities) {
                if (endpointSecurity.isArray()) {
                    ArrayNode securityArray = (ArrayNode) endpointSecurity;
                    for (int i = 0; i < securityArray.size(); i++) {
                        String securityName = securityArray.get(i).fieldNames().next();
                        if (!securityDefinitionName.get().equals(securityName)) {
                            securityArray.remove(i);
                        }
                    }
                } else {
                    // Security section must be an array
                    throw new IllegalArgumentException("Swagger/OpenAPI specification requires endpoint security to be an array of elements!");
                }
            }
            return OBJECT_MAPPER.writeValueAsString(rootNode);
        }
    }

    // no changes
    LOG.debug("Specification was provided with no security method");
    return specification;
}
 
源代码4 项目: camunda-spin   文件: JacksonJsonNode.java
public SpinJsonNode removeAt(int index) {
  if(this.isArray()) {
    ArrayNode node = (ArrayNode) jsonNode;

    node.remove(getCorrectIndex(index));

    return this;
  } else {
    throw LOG.unableToModifyNode(jsonNode.getNodeType().name());
  }
}
 
源代码5 项目: onos   文件: BgpConfig.java
/**
 * Removes BGP speaker from configuration.
 *
 * @param speakerName BGP speaker name
 */
public void removeSpeaker(String speakerName) {
    ArrayNode speakersArray = (ArrayNode) object.get(SPEAKERS);

    for (int i = 0; i < speakersArray.size(); i++) {
        if (speakersArray.get(i).hasNonNull(NAME) &&
                speakersArray.get(i).get(NAME).asText().equals(speakerName)) {
            speakersArray.remove(i);
            return;
        }
    }
}
 
源代码6 项目: onos   文件: VplsAppConfig.java
/**
 * Removes a VPLS from the configuration.
 *
 * @param vplsName the vplsName of the VPLS to be removed
 */
public void removeVpls(String vplsName) {
    ArrayNode configuredVpls = (ArrayNode) object.get(VPLS);

    for (int i = 0; i < configuredVpls.size(); i++) {
        if (configuredVpls.get(i).hasNonNull(NAME) &&
                configuredVpls.get(i).get(NAME).asText().equals(vplsName)) {
            configuredVpls.remove(i);
            return;
        }
    }
}
 
源代码7 项目: keycloak   文件: ReflectionUtil.java
private static void removeArrayItem(ArrayNode list, int index) {
    if (index == -1) {
        throw new IllegalArgumentException("Internal error - should never be called with index == -1");
    }
    list.remove(index);
}
 
源代码8 项目: timbuctoo   文件: TinkerPopOperations.java
@Override
public int deleteEntity(Collection collection, UUID id, Change modified)
  throws NotFoundException {

  requireCommit = true;

  GraphTraversal<Vertex, Vertex> entityTraversal = entityFetcher.getEntity(traversal, id, null,
    collection.getCollectionName());

  if (!entityTraversal.hasNext()) {
    throw new NotFoundException();
  }

  Vertex entity = entityTraversal.next();
  String entityTypesStr = getProp(entity, "types", String.class).orElse("[]");
  boolean wasRemoved = false;
  if (entityTypesStr.contains("\"" + collection.getEntityTypeName() + "\"")) {
    try {
      ArrayNode entityTypes = arrayToEncodedArray.tinkerpopToJson(entityTypesStr);
      if (entityTypes.size() == 1) {
        entity.property("deleted", true);
        wasRemoved = true;
      } else {
        for (int i = entityTypes.size() - 1; i >= 0; i--) {
          JsonNode val = entityTypes.get(i);
          if (val != null && val.asText("").equals(collection.getEntityTypeName())) {
            entityTypes.remove(i);
            wasRemoved = true;
          }
        }
        entity.property("types", entityTypes.toString());
      }
    } catch (IOException e) {
      LOG.error(Logmarkers.databaseInvariant, "property 'types' was not parseable: " + entityTypesStr);
    }
  } else {
    throw new NotFoundException();
  }

  int newRev = getProp(entity, "rev", Integer.class).orElse(1) + 1;
  entity.property("rev", newRev);

  entity.edges(Direction.BOTH).forEachRemaining(edge -> {
    // Skip the hasEntity and the VERSION_OF edge, which are not real relations, but system edges
    if (edge.label().equals(HAS_ENTITY_RELATION_NAME) || edge.label().equals(VERSION_OF)) {
      return;
    }
    Optional<Collection> ownEdgeCol = getOwnCollectionOfElement(collection.getVre(), edge);
    if (ownEdgeCol.isPresent()) {
      edge.property(ownEdgeCol.get().getEntityTypeName() + "_accepted", false);
    }
  });

  setModified(entity, modified);
  entity.property("pid").remove();

  Vertex duplicate = duplicateVertex(traversal, entity, indexHandler);

  if (wasRemoved) {
    listener.onRemoveFromCollection(collection, Optional.of(entity), duplicate);
  }

  return newRev;
}