本文整理了Java中com.fasterxml.jackson.databind.node.ArrayNode.remove()
方法的一些代码示例,展示了ArrayNode.remove()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayNode.remove()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.node.ArrayNode
类名称:ArrayNode
方法名:remove
[英]Method for removing an entry from this ArrayNode. Will return value of the entry at specified index, if entry existed; null if not.
[中]用于从此ArrayNode中删除条目的方法。若条目存在,将返回指定索引处条目的值;如果不是,则为null。
代码示例来源:origin: json-path/JsonPath
public void removeProperty(Object obj, Object key) {
if (isMap(obj))
toJsonObject(obj).remove(key.toString());
else {
ArrayNode array = toJsonArray(obj);
int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
array.remove(index);
}
}
代码示例来源:origin: embulk/embulk
private static void mergeJsonArray(ArrayNode src, ArrayNode other) {
for (int i = 0; i < other.size(); i++) {
JsonNode s = src.get(i);
JsonNode v = other.get(i);
if (s == null) {
src.add(v);
} else if (v.isObject() && s.isObject()) {
mergeJsonObject((ObjectNode) s, (ObjectNode) v);
} else if (v.isArray() && s.isArray()) {
mergeJsonArray((ArrayNode) s, (ArrayNode) v);
} else {
src.remove(i);
src.insert(i, v);
}
}
}
代码示例来源:origin: com.jayway.jsonpath/json-path
public void removeProperty(Object obj, Object key) {
if (isMap(obj))
toJsonObject(obj).remove(key.toString());
else {
ArrayNode array = toJsonArray(obj);
int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
array.remove(index);
}
}
代码示例来源:origin: com.github.foodev/jsondiff
@Override
public void remove(int index) {
wrapped.remove(index);
}
代码示例来源:origin: algesten/jsondiff
@Override
public void remove(int index) {
wrapped.remove(index);
}
代码示例来源:origin: org.keycloak/keycloak-admin-cli
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);
}
代码示例来源:origin: io.fabric8/zjsonpatch
private static void remove(JsonNode node, List<String> path) {
if (path.isEmpty()) {
throw new RuntimeException("[Remove Operation] path is empty");
} else {
JsonNode parentNode = getParentNode(node, path);
if (parentNode == null) {
throw new RuntimeException("[Remove Operation] noSuchPath in source, path provided : " + path);
} else {
String fieldToRemove = path.get(path.size() - 1).replaceAll("\"", "");
if (parentNode.isObject())
((ObjectNode) parentNode).remove(fieldToRemove);
else
((ArrayNode) parentNode).remove(Integer.parseInt(fieldToRemove));
}
}
}
代码示例来源:origin: org.onosproject/onos-app-routing-api
/**
* 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;
}
}
}
代码示例来源:origin: stackoverflow.com
ArrayNode arrayNode = (ArrayNode) mapper.readTree(this.getScrape().getScrapetext());
A a = mapper.readValue(arrayNode.get(0), A.class);
arrayNode.remove(0);
List<B> b = mapper.readValue(arrayNode.toString(), new TypeReference<List<B>>()
{
});
代码示例来源:origin: com.github.lafa.jsonpath/json-path
@Override
public void removeProperty(Object obj, Object key) {
if (isMap(obj))
toJsonObject(obj).remove(key.toString());
else {
ArrayNode array = toJsonArray(obj);
int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
array.remove(index);
}
}
代码示例来源:origin: com.flipkart.zjsonpatch/zjsonpatch
@Override
public void remove(List<String> path) {
if (path.isEmpty()) {
error(Operation.REMOVE, "path is empty");
} else {
JsonNode parentNode = getParentNode(path, Operation.REMOVE);
String fieldToRemove = path.get(path.size() - 1).replaceAll("\"", "");
if (parentNode.isObject())
((ObjectNode) parentNode).remove(fieldToRemove);
else if (parentNode.isArray())
((ArrayNode) parentNode).remove(arrayIndex(fieldToRemove, parentNode.size() - 1, flags.contains(CompatibilityFlags.REMOVE_NONE_EXISTING_ARRAY_ELEMENT)));
else
error(Operation.REMOVE, "noSuchPath in source, path provided : " + PathUtils.getPathRepresentation(path));
}
}
代码示例来源:origin: flipkart-incubator/zjsonpatch
@Override
public void remove(List<String> path) {
if (path.isEmpty()) {
error(Operation.REMOVE, "path is empty");
} else {
JsonNode parentNode = getParentNode(path, Operation.REMOVE);
String fieldToRemove = path.get(path.size() - 1).replaceAll("\"", "");
if (parentNode.isObject())
((ObjectNode) parentNode).remove(fieldToRemove);
else if (parentNode.isArray())
((ArrayNode) parentNode).remove(arrayIndex(fieldToRemove, parentNode.size() - 1, flags.contains(CompatibilityFlags.REMOVE_NONE_EXISTING_ARRAY_ELEMENT)));
else
error(Operation.REMOVE, "noSuchPath in source, path provided : " + PathUtils.getPathRepresentation(path));
}
}
代码示例来源:origin: line/centraldogma
@Override
JsonNode apply(final JsonNode node) {
if (path.toString().isEmpty()) {
return MissingNode.getInstance();
}
ensureExistence(node);
final JsonNode parentNode = node.at(path.head());
final String raw = path.last().getMatchingProperty();
if (parentNode.isObject()) {
((ObjectNode) parentNode).remove(raw);
} else {
((ArrayNode) parentNode).remove(Integer.parseInt(raw));
}
return node;
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
@Override
JsonNode apply(final JsonNode node) {
if (path.toString().isEmpty()) {
return MissingNode.getInstance();
}
ensureExistence(node);
final JsonNode parentNode = node.at(path.head());
final String raw = path.last().getMatchingProperty();
if (parentNode.isObject()) {
((ObjectNode) parentNode).remove(raw);
} else {
((ArrayNode) parentNode).remove(Integer.parseInt(raw));
}
return node;
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded
@Override
JsonNode apply(final JsonNode node) {
if (path.toString().isEmpty()) {
return MissingNode.getInstance();
}
ensureExistence(node);
final JsonNode parentNode = node.at(path.head());
final String raw = path.last().getMatchingProperty();
if (parentNode.isObject()) {
((ObjectNode) parentNode).remove(raw);
} else {
((ArrayNode) parentNode).remove(Integer.parseInt(raw));
}
return node;
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded
@Override
JsonNode apply(final JsonNode node) {
if (path.toString().isEmpty()) {
return MissingNode.getInstance();
}
final JsonNode found = node.at(path);
if (found.isMissingNode()) {
return node;
}
final JsonNode parentNode = node.at(path.head());
final String raw = path.last().getMatchingProperty();
if (parentNode.isObject()) {
((ObjectNode) parentNode).remove(raw);
} else if (parentNode.isArray()) {
((ArrayNode) parentNode).remove(Integer.parseInt(raw));
}
return node;
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
@Override
JsonNode apply(final JsonNode node) {
if (path.toString().isEmpty()) {
return MissingNode.getInstance();
}
final JsonNode found = node.at(path);
if (found.isMissingNode()) {
return node;
}
final JsonNode parentNode = node.at(path.head());
final String raw = path.last().getMatchingProperty();
if (parentNode.isObject()) {
((ObjectNode) parentNode).remove(raw);
} else if (parentNode.isArray()) {
((ArrayNode) parentNode).remove(Integer.parseInt(raw));
}
return node;
}
代码示例来源:origin: line/centraldogma
@Override
JsonNode apply(final JsonNode node) {
if (path.toString().isEmpty()) {
return MissingNode.getInstance();
}
final JsonNode found = node.at(path);
if (found.isMissingNode()) {
return node;
}
final JsonNode parentNode = node.at(path.head());
final String raw = path.last().getMatchingProperty();
if (parentNode.isObject()) {
((ObjectNode) parentNode).remove(raw);
} else if (parentNode.isArray()) {
((ArrayNode) parentNode).remove(Integer.parseInt(raw));
}
return node;
}
代码示例来源:origin: liveoak-io/liveoak
default void removeConfig(Resource resource, File configRoot) throws IOException {
File configFile = configFile(resource, configRoot);
if (hasOwnConfigFile()) {
// TODO Delete the file
} else {
JsonNode tree = read(configFile);
if (tree.isArray()) {
int index = findExisting((ArrayNode) tree, resource.id());
if (index != -1) {
((ArrayNode) tree).remove(index);
write(configFile, tree);
}
}
}
}
代码示例来源:origin: java-json-tools/json-patch
@Override
public JsonNode apply(final JsonNode node)
throws JsonPatchException
{
if (path.isEmpty())
return MissingNode.getInstance();
if (path.path(node).isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchPath"));
final JsonNode ret = node.deepCopy();
final JsonNode parentNode = path.parent().get(ret);
final String raw = Iterables.getLast(path).getToken().getRaw();
if (parentNode.isObject())
((ObjectNode) parentNode).remove(raw);
else
((ArrayNode) parentNode).remove(Integer.parseInt(raw));
return ret;
}
内容来源于网络,如有侵权,请联系作者删除!