本文整理了Java中com.fasterxml.jackson.databind.node.ArrayNode.removeAll()
方法的一些代码示例,展示了ArrayNode.removeAll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayNode.removeAll()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.node.ArrayNode
类名称:ArrayNode
方法名:removeAll
[英]Method for removing all elements of this array, leaving the array empty.
[中]方法删除此数组的所有元素,使数组为空。
代码示例来源:origin: dropwizard/dropwizard
if (node.get(key) != null && node.get(key).isArray()) {
final ArrayNode arrayNode = (ArrayNode) obj.get(key);
arrayNode.removeAll();
Arrays.stream(ESCAPED_COMMA_SPLIT_PATTERN.split(value))
.map(String::trim)
代码示例来源:origin: java-json-tools/json-schema-validator
schemas.removeAll();
代码示例来源:origin: HubSpot/Singularity
private static void merge(ObjectNode to, ObjectNode from) {
Iterator<String> newFieldNames = from.fieldNames();
while (newFieldNames.hasNext()) {
String newFieldName = newFieldNames.next();
JsonNode oldVal = to.get(newFieldName);
JsonNode newVal = from.get(newFieldName);
if (oldVal == null || oldVal.isNull()) {
to.set(newFieldName, newVal);
} else if (oldVal.isArray() && newVal.isArray()) {
((ArrayNode) oldVal).removeAll();
((ArrayNode) oldVal).addAll((ArrayNode) newVal);
} else if (oldVal.isObject() && newVal.isObject()) {
merge((ObjectNode) oldVal, (ObjectNode) newVal);
} else if (!(newVal == null || newVal.isNull())) {
to.set(newFieldName, newVal);
}
}
}
}
代码示例来源:origin: io.macgyver/macgyver-core
public static void sort(ArrayNode array, Comparator<JsonNode> comparator) {
Preconditions.checkNotNull(array);
Preconditions.checkNotNull(comparator);
List<JsonNode> arr = Lists.newArrayList();
for (JsonNode n : array) {
arr.add(n);
}
Collections.sort(arr, comparator);
array.removeAll();
for (JsonNode n : arr) {
array.add(n);
}
}
代码示例来源:origin: com.hubspot/SingularityService
private static void merge(ObjectNode to, ObjectNode from) {
Iterator<String> newFieldNames = from.fieldNames();
while (newFieldNames.hasNext()) {
String newFieldName = newFieldNames.next();
JsonNode oldVal = to.get(newFieldName);
JsonNode newVal = from.get(newFieldName);
if (oldVal == null || oldVal.isNull()) {
to.set(newFieldName, newVal);
} else if (oldVal.isArray() && newVal.isArray()) {
((ArrayNode) oldVal).removeAll();
((ArrayNode) oldVal).addAll((ArrayNode) newVal);
} else if (oldVal.isObject() && newVal.isObject()) {
merge((ObjectNode) oldVal, (ObjectNode) newVal);
} else if (!(newVal == null || newVal.isNull())) {
to.set(newFieldName, newVal);
}
}
}
}
代码示例来源:origin: io.macgyver/macgyver-core
public void sort(MenuItem m) {
List<MenuItem> tmp = getItems();
Collections.sort(tmp, comparator);
ArrayNode n = (ArrayNode) m.getModel().get("items");
n.removeAll();
for (MenuItem t : tmp) {
n.add(t.getModel());
}
tmp.stream().forEach(it -> {
it.sort();
});
}
}
代码示例来源:origin: stackoverflow.com
public class Tags {
public static void main(String[] args) throws Exception {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("tags.json");
ObjectMapper om = new ObjectMapper();
JsonNode node = om.readTree(in);
recursiveFind(node);
System.out.println(node); //Prints {"test1":{"get":{"tags":["my rest calls"]}},"test2":{"put":{"tags":["my rest calls"]}}}
}
private static void recursiveFind(JsonNode node) {
if (!node.isObject()) {
return;
}
JsonNode tags = node.get("tags");
if (tags != null) {
ArrayNode arry = (ArrayNode) tags;
arry.removeAll();
arry.add("my rest calls");
}
Iterator<JsonNode> it = node.elements();
while (it.hasNext()) {
JsonNode jsonNode = it.next();
recursiveFind(jsonNode);
}
}
}
代码示例来源:origin: org.apache.knox/gateway-provider-rewrite
private void processEndObject() throws IOException {
Level child;
Level parent;
child = stack.pop();
if( bufferingLevel == child ) {
filterBufferedNode( child );
mapper.writeTree( generator, child.node );
bufferingLevel = null;
bufferingConfig = null;
} else if( bufferingLevel == null ) {
generator.writeEndObject();
if( !stack.isEmpty() ) {
parent = stack.peek();
switch( parent.node.asToken() ) {
case START_ARRAY:
((ArrayNode)parent.node ).removeAll();
break;
case START_OBJECT:
((ObjectNode)parent.node ).removeAll();
break;
default:
throw new IllegalStateException();
}
}
}
}
代码示例来源:origin: lightblue-platform/lightblue-core
while (accessNodes.hasNext()) {
ArrayNode child = (ArrayNode) accessNodes.next();
child.removeAll();
child.add("anyone");
代码示例来源:origin: org.apache.knox/gateway-provider-rewrite
array.set( array.size()-1, new TextNode( value ) );
} else {
array.removeAll();
((ArrayNode)parent.node).removeAll();
} else {
((ObjectNode)parent.node).removeAll();
代码示例来源:origin: apache/knox
private void processEndObject() throws IOException {
Level child;
Level parent;
child = stack.pop();
if( child.equals(bufferingLevel) ) {
filterBufferedNode( child );
mapper.writeTree( generator, child.node );
bufferingLevel = null;
bufferingConfig = null;
} else if( bufferingLevel == null ) {
generator.writeEndObject();
if( !stack.isEmpty() ) {
parent = stack.peek();
switch( parent.node.asToken() ) {
case START_ARRAY:
((ArrayNode)parent.node ).removeAll();
break;
case START_OBJECT:
((ObjectNode)parent.node ).removeAll();
break;
default:
throw new IllegalStateException();
}
}
}
}
代码示例来源:origin: apache/knox
array.set( array.size()-1, new TextNode( value ) );
} else {
array.removeAll();
((ArrayNode)parent.node).removeAll();
} else {
((ObjectNode)parent.node).removeAll();
代码示例来源:origin: apache/knox
private void processValueNull() throws IOException {
Level child;
if(stack.isEmpty()) {
generator.writeNull();
return;
}
Level parent = stack.peek();
if( parent.isArray() ) {
((ArrayNode)parent.node ).addNull();
//dump();
if( bufferingLevel == null ) {
((ArrayNode)parent.node ).removeAll();
}
} else {
child = stack.pop();
parent = stack.peek();
((ObjectNode)parent.node ).putNull( child.field );
//dump();
if( bufferingLevel == null ) {
((ObjectNode)parent.node ).remove( child.field );
}
}
if( bufferingLevel == null ) {
generator.writeNull();
}
}
代码示例来源:origin: org.apache.knox/gateway-provider-rewrite
private void processEndArray() throws IOException {
Level child;
Level parent;
child = stack.pop();
if( bufferingLevel == child ) {
filterBufferedNode( child );
mapper.writeTree( generator, child.node );
bufferingLevel = null;
bufferingConfig = null;
} else if( bufferingLevel == null ) {
generator.writeEndArray();
if( !stack.isEmpty() ) {
parent = stack.peek();
switch( parent.node.asToken() ) {
case START_ARRAY:
((ArrayNode)parent.node ).removeAll();
break;
case START_OBJECT:
((ObjectNode)parent.node ).removeAll();
break;
default:
throw new IllegalStateException();
}
}
}
}
代码示例来源:origin: org.apache.knox/gateway-provider-rewrite
private void processValueNull() throws IOException {
Level child;
if(stack.isEmpty()) {
generator.writeNull();
return;
}
Level parent = stack.peek();
if( parent.isArray() ) {
((ArrayNode)parent.node ).addNull();
//dump();
if( bufferingLevel == null ) {
((ArrayNode)parent.node ).removeAll();
}
} else {
child = stack.pop();
parent = stack.peek();
((ObjectNode)parent.node ).putNull( child.field );
//dump();
if( bufferingLevel == null ) {
((ObjectNode)parent.node ).remove( child.field );
}
}
if( bufferingLevel == null ) {
generator.writeNull();
}
}
代码示例来源:origin: apache/knox
private void processEndArray() throws IOException {
Level child;
Level parent;
child = stack.pop();
if( child.equals(bufferingLevel) ) {
filterBufferedNode( child );
mapper.writeTree( generator, child.node );
bufferingLevel = null;
bufferingConfig = null;
} else if( bufferingLevel == null ) {
generator.writeEndArray();
if( !stack.isEmpty() ) {
parent = stack.peek();
switch( parent.node.asToken() ) {
case START_ARRAY:
((ArrayNode)parent.node ).removeAll();
break;
case START_OBJECT:
((ObjectNode)parent.node ).removeAll();
break;
default:
throw new IllegalStateException();
}
}
}
}
代码示例来源:origin: io.swagger/swagger-compat-spec-parser
/**
* Apply a migrator to all elements of the array at the current pointer
*
* <p>Note that if the migrator fails to apply to at least one element, the
* original array is left untouched; its elements are replaced if and only
* if the migrator applies successfully to <strong>all</strong> elements.
* </p>
*
* @param migrator the migrator to apply
* @throws SwaggerMigrationException current node is not a JSON Array, or
* migrator failed to apply to at least one array element
*/
public void applyMigratorToElements(final SwaggerMigrator migrator)
throws SwaggerMigrationException {
if (!currentNode.isArray()) {
throw new SwaggerMigrationException();
}
final ArrayNode array = (ArrayNode) currentNode;
final ArrayNode transformed = array.arrayNode();
for (final JsonNode element : array) {
transformed.add(migrator.migrate(element));
}
array.removeAll().addAll(transformed);
}
代码示例来源:origin: io.syndesis.server/server-connector-generator
operationNode.remove("parameters");
} else {
parameters.removeAll();
parameters.addAll(parametersList);
代码示例来源:origin: org.apache.knox/gateway-provider-rewrite
private void processValueBoolean() throws IOException {
Level child;
Level parent;
if(stack.isEmpty()) {
generator.writeBoolean(parser.getBooleanValue());
return;
}
parent = stack.peek();
if( parent.isArray() ) {
((ArrayNode)parent.node ).add( parser.getBooleanValue() );
//dump();
if( bufferingLevel == null ) {
((ArrayNode)parent.node ).removeAll();
}
} else {
child = stack.pop();
parent = stack.peek();
((ObjectNode)parent.node ).put( child.field, parser.getBooleanValue() );
//dump();
if( bufferingLevel == null ) {
((ObjectNode)parent.node ).remove( child.field );
}
}
if( bufferingLevel == null ) {
generator.writeBoolean( parser.getBooleanValue() );
}
}
代码示例来源:origin: apache/knox
private void processValueBoolean() throws IOException {
Level child;
Level parent;
if(stack.isEmpty()) {
generator.writeBoolean(parser.getBooleanValue());
return;
}
parent = stack.peek();
if( parent.isArray() ) {
((ArrayNode)parent.node ).add( parser.getBooleanValue() );
//dump();
if( bufferingLevel == null ) {
((ArrayNode)parent.node ).removeAll();
}
} else {
child = stack.pop();
parent = stack.peek();
((ObjectNode)parent.node ).put( child.field, parser.getBooleanValue() );
//dump();
if( bufferingLevel == null ) {
((ObjectNode)parent.node ).remove( child.field );
}
}
if( bufferingLevel == null ) {
generator.writeBoolean( parser.getBooleanValue() );
}
}
内容来源于网络,如有侵权,请联系作者删除!