/** * Recursively remove all null nodes in the given json subtree * * This method operates on the given root node, and returns the same root * instance. It does not create a new copy. */ public static JsonNode filterNulls(JsonNode root) { if (root instanceof ArrayNode) { for (JsonNode element : root) { filterNulls(element); } } else if (root instanceof ObjectNode) { ObjectNode o = (ObjectNode) root; for (Iterator<Map.Entry<String, JsonNode>> itr = o.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> entry = itr.next(); JsonNode value = entry.getValue(); if (value == null || value instanceof NullNode) { itr.remove(); } else { filterNulls(value); } } } return root; }
/** * Recursively remove all null nodes in the given json subtree * * This method operates on the given root node, and returns the same root * instance. It does not create a new copy. */ public static JsonNode filterNulls(JsonNode root) { if (root instanceof ArrayNode) { for (JsonNode element : root) { filterNulls(element); } } else if (root instanceof ObjectNode) { ObjectNode o = (ObjectNode) root; for (Iterator<Map.Entry<String, JsonNode>> itr = o.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> entry = itr.next(); JsonNode value = entry.getValue(); if (value == null || value instanceof NullNode) { itr.remove(); } else { filterNulls(value); } } } return root; }
private boolean updateDoc(EntityMetadata md, JsonDoc doc, Measure measure) { if (updater.update(doc, md.getFieldTreeRoot(), Path.EMPTY)) { // Remove any nulls from the document JsonDoc.filterNulls(doc.getRoot()); measure.begin("updateArraySizes"); PredefinedFields.updateArraySizes(md, nodeFactory, doc); measure.end("updateArraySizes"); return true; } else { return false; } }
request.getEntityVersion().getEntity(), factory, request instanceof DocRequest ? JsonDoc.docList(JsonDoc.filterNulls(((DocRequest) request).getEntityData())) : null, request.getExecution()); this.request = request;
request.getEntityVersion().getEntity(), factory, request instanceof DocRequest ? JsonDoc.docList(JsonDoc.filterNulls(((DocRequest) request).getEntityData())) : null, request.getExecution()); this.request = request;