public ObjectCursor(JsonNode n, NodeCursor p) { super(JsonStreamContext.TYPE_OBJECT, p); _contents = ((ObjectNode) n).fields(); _needEntry = true; }
@JsonAnyGetter public Map<String,JsonNode> _anyGetter() { Map<String, JsonNode> unknowns = new HashMap<String, JsonNode>(); for(Iterator<Entry<String, JsonNode>> i = objectNode.fields(); i.hasNext(); ){ Entry<String, JsonNode> e = i.next(); unknowns.put(e.getKey(), e.getValue()); } return unknowns; }
@Override public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { ObjectMapper mapper = (ObjectMapper) p.getCodec(); ObjectNode root = mapper.readTree(p); Iterator<Map.Entry<String, JsonNode>> iterator = root.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); if (entry.getKey().equals(TYPE_KEY)) { Class<? extends T> configClass = concreteFactory.apply(entry.getValue().asText()); root.remove(TYPE_KEY); return mapper.convertValue(root, configClass); } } throw new ConfigurationException("Failed to deserialize polymorphic " + _valueClass.getSimpleName() + " configuration"); } }
private static void mergeJsonObject(ObjectNode src, ObjectNode other) { Iterator<Map.Entry<String, JsonNode>> ite = other.fields(); while (ite.hasNext()) { Map.Entry<String, JsonNode> pair = ite.next(); JsonNode s = src.get(pair.getKey()); JsonNode v = pair.getValue(); if (v.isObject() && s != null && s.isObject()) { mergeJsonObject((ObjectNode) s, (ObjectNode) v); } else if (v.isArray() && s != null && s.isArray()) { mergeJsonArray((ArrayNode) s, (ArrayNode) v); } else { src.replace(pair.getKey(), v); } } }
ObjectNode jsonNodes = mapper.readTree(jsonParser); Iterator<Map.Entry<String, JsonNode>> jsonNodeIterator = jsonNodes.fields();
@JsonCreator private static PluginType create(final JsonNode typeJson) { if (typeJson.isTextual()) { return createFromString(((TextNode) typeJson).textValue()); } else if (typeJson.isObject()) { final HashMap<String, String> stringMap = new HashMap<String, String>(); final ObjectNode typeObject = (ObjectNode) typeJson; final Iterator<Map.Entry<String, JsonNode>> fieldIterator = typeObject.fields(); while (fieldIterator.hasNext()) { final Map.Entry<String, JsonNode> field = fieldIterator.next(); final JsonNode fieldValue = field.getValue(); if (fieldValue instanceof ContainerNode) { throw new IllegalArgumentException("\"type\" must be a string or a 1-depth mapping."); } stringMap.put(field.getKey(), fieldValue.textValue()); } return createFromStringMap(stringMap); } else { throw new IllegalArgumentException("\"type\" must be a string or a 1-depth mapping."); } }
@Nullable @Override public HttpHeaders deserialize(JsonParser p, DeserializationContext ctx) throws IOException { final JsonNode tree = p.getCodec().readTree(p); if (!tree.isObject()) { ctx.reportInputMismatch(HttpHeaders.class, "HTTP headers must be an object."); return null; } final ObjectNode obj = (ObjectNode) tree; final HttpHeaders headers = HttpHeaders.of(); for (final Iterator<Entry<String, JsonNode>> i = obj.fields(); i.hasNext();) { final Entry<String, JsonNode> e = i.next(); final AsciiString name = HttpHeaderNames.of(e.getKey()); final JsonNode values = e.getValue(); if (!values.isArray()) { // Values is a single item, so add it directly. addHeader(ctx, headers, name, values); } else { final int numValues = values.size(); for (int j = 0; j < numValues; j++) { final JsonNode v = values.get(j); addHeader(ctx, headers, name, v); } } } return headers.asImmutable(); }
ObjectNode root = (ObjectNode) mapper.readTree(jp); Iterator<Map.Entry<String, JsonNode>> elementsIterator = root.fields(); DataDTO dataDTO = new DataDTO(); ExpressionDTO expressionDTO = new ExpressionDTO();
newHistory[history.length] = node; ObjectNode c = ( ObjectNode ) node; Iterator<Entry<String, JsonNode>> i = c.fields(); while ( i.hasNext() ) { Entry<String, JsonNode> e = i.next();
public static void stripEmptyContainerNodes(ObjectNode objectNode) { Iterator<Map.Entry<String, JsonNode>> i = objectNode.fields(); while (i.hasNext()) { Map.Entry<String, JsonNode> entry = i.next(); JsonNode value = entry.getValue(); if (value instanceof ContainerNode && ((ContainerNode<?>) value).size() == 0) { // remove empty nodes, e.g. unused "smtp" and "alerts" nodes i.remove(); } } }
private Iterable<Map.Entry<String, JsonNode>> strip(Iterable<Map.Entry<String, JsonNode>> fields) { ObjectNode properties = JsonHelper.jsonObject(); for (Map.Entry<String, JsonNode> entry : fields) { String key = stripName(entry.getKey(), "property"); if (key.equals("id")) { key = "_id"; } properties.set(key, entry.getValue()); } return () -> properties.fields(); }
private static ObjectNode getOrderedObjectNode(ObjectNode objectNode, List<String> keyOrder) { Map<String, JsonNode> map = Maps.newHashMap(); Iterator<Map.Entry<String, JsonNode>> i = objectNode.fields(); while (i.hasNext()) { Map.Entry<String, JsonNode> entry = i.next(); map.put(entry.getKey(), entry.getValue()); } ObjectNode orderedObjectNode = mapper.createObjectNode(); for (Map.Entry<String, JsonNode> entry : new ExplicitOrdering(keyOrder) .sortedCopy(map.entrySet())) { orderedObjectNode.set(entry.getKey(), entry.getValue()); } return orderedObjectNode; }
@Override public void setUserProperties(String project, Object userId, ObjectNode properties) { try (Connection conn = queryExecutor.getConnection()) { setUserProperties(conn, project, userId, () -> properties.fields(), false); } catch (SQLException e) { throw Throwables.propagate(e); } }
@Override public void setUserPropertiesOnce(String project, Object userId, ObjectNode properties) { try (Connection conn = queryExecutor.getConnection()) { setUserProperties(conn, project, userId, () -> properties.fields(), true); } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public Object create(String project, Object id, ObjectNode properties) { try (Connection conn = queryExecutor.getConnection()) { return createInternal(conn, project, id, () -> properties.fields()); } catch (SQLException e) { throw new RuntimeException(e); } }
private void cleanup() { Iterator<Entry<String, JsonNode>> fields = definesNode.fields(); while (fields.hasNext()) { Entry<String, JsonNode> entry = fields.next(); if (entry.getValue().get("fields").size() == 0) { fields.remove(); } } fields = definesNode.fields(); while (fields.hasNext()) { Entry<String, JsonNode> entry = fields.next(); ArrayNode includes = (ArrayNode) entry.getValue().get("includes"); Iterator<JsonNode> includesIterator = includes.iterator(); while (includesIterator.hasNext()) { JsonNode includeNode = includesIterator.next(); if (!definesNode.has(includeNode.asText())) { // TODO replace the include with the closest super-type? Or don't allow deleting defines that are explicitly referenced (although no fields) includesIterator.remove(); } } } }
private Map<String, AttributeValue> generatePutRequest(String project, Object id, ObjectNode properties) { Map<String, AttributeValue> builder = new HashMap<>(); builder.put("project", new AttributeValue(project)); builder.put("id", new AttributeValue(id.toString())); Map<String, AttributeValue> props = new HashMap<>(); Iterator<Entry<String, JsonNode>> fields = properties.fields(); while (fields.hasNext()) { Entry<String, JsonNode> next = fields.next(); props.put(next.getKey(), convertAttributeValue(next.getValue())); } builder.put("properties", new AttributeValue().withM(props)); return builder; }
private void collectVarargsFromNode(JsonNode node) { if (node.isArray()) { ArrayNode arrayNode = ArrayNode.class.cast(node); for (int i = 0; i < node.size(); i++) { addArgument(arrayNode.get(i)); } } if (node.isObject()) { ObjectNode objectNode = ObjectNode.class.cast(node); Iterator<Map.Entry<String,JsonNode>> items = objectNode.fields(); while (items.hasNext()) { Map.Entry<String,JsonNode> item = items.next(); JsonNode name = JsonNodeFactory.instance.objectNode().put(item.getKey(),item.getKey()); addArgument(name.get(item.getKey())); addArgument(item.getValue()); } } }
private void parseProperties(QueryPart queryPart, ObjectNode properties) throws QueryException { Iterator<Entry<String, JsonNode>> fields = properties.fields(); while (fields.hasNext()) { Entry<String, JsonNode> entry = fields.next(); if (value.isObject()) { ObjectNode set = (ObjectNode)value; Iterator<Entry<String, JsonNode>> propertySetFields = set.fields(); while (propertySetFields.hasNext()) { Entry<String, JsonNode> propertyEntry = propertySetFields.next();
Iterator<Entry<String, JsonNode>> fields = node.fields(); Class<?> keyType = typeOrObject(type.getComponentType()); TypeInformation<?> valueType = type.getMapValueType();