Java Code Examples for com.fasterxml.jackson.databind.node.ArrayNode#set()
The following examples show how to use
com.fasterxml.jackson.databind.node.ArrayNode#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonCacheImpl.java From openapi-generator with Apache License 2.0 | 5 votes |
@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; }
Example 2
Source File: JsonNodeELResolver.java From flowable-engine with Apache License 2.0 | 5 votes |
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); }
Example 3
Source File: JsonFilterReader.java From knox with Apache License 2.0 | 5 votes |
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 ); } }
Example 4
Source File: ReflectionUtil.java From keycloak with Apache License 2.0 | 5 votes |
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); }