/** * The generateFacetsForLeaves() method for processing json arrays, simply delegates for each array element. */ private void generateFacetsForLeaves(ArrayNode array, String fieldName, ExtendedJsonField field, String path, List<SirenFacetEntry> facets) { Iterator<JsonNode> iterator = array.getElements(); while (iterator.hasNext()) { JsonNode node = iterator.next(); generateFacetsForLeaves(node, fieldName, field, path, facets); } }
public static List<String> getStrings(JsonNode node, String prop, List<String> defaultValue) throws JsonFormatException { ArrayNode arrayNode = getArray(node, prop, null); if (arrayNode == null) { return defaultValue; } List<String> elements = new ArrayList<String>(); Iterator<JsonNode> elementItr = arrayNode.getElements(); while (elementItr.hasNext()) { elements.add(elementItr.next().getValueAsText()); } return elements; } }
public static List<String> getStrings(JsonNode node, String prop, List<String> defaultValue) throws JsonFormatException { ArrayNode arrayNode = getArray(node, prop, null); if (arrayNode == null) { return defaultValue; } List<String> elements = new ArrayList<String>(); Iterator<JsonNode> elementItr = arrayNode.getElements(); while (elementItr.hasNext()) { elements.add(elementItr.next().asText()); } return elements; }
public List<IndexerDefinitionBuilder> fromJsonBytes(byte [] json) { List<IndexerDefinitionBuilder> builders = new ArrayList<IndexerDefinitionBuilder>(); ArrayNode node; try { node = (ArrayNode) new ObjectMapper().readTree(new ByteArrayInputStream(json)); } catch (IOException e) { throw new RuntimeException("Error parsing indexer definition JSON.", e); } Iterator<JsonNode> it = node.getElements(); while (it.hasNext()) { JsonNode nextNode = it.next(); builders.add(IndexerDefinitionJsonSerDeser.INSTANCE.fromJson((ObjectNode)nextNode)); } return builders; } }
ArrayNode users = (ArrayNode) root.path("users"); Iterator<JsonNode> iterator = users.getElements(); while (iterator.hasNext()) { User user = mapper.readValue(iterator.next(), User.class);
public static List<String> getStrings(JsonNode node, String prop, List<String> defaultValue) throws JsonFormatException { ArrayNode arrayNode = getArray(node, prop, null); if (arrayNode == null || arrayNode.isNull()) { return defaultValue; } List<String> elements = new ArrayList<String>(); Iterator<JsonNode> elementItr = arrayNode.getElements(); while (elementItr.hasNext()) { elements.add(elementItr.next().getValueAsText()); } return elements; } }
public static List<UserTagList> parse(ArrayNode arrayNode) { List<UserTagList> result = new ArrayList<UserTagList>(arrayNode.size()); Iterator<JsonNode> elements = arrayNode.getElements(); while (elements.hasNext()) { JsonNode json = elements.next(); long userId = json.get("id").asLong(); List<Tag> tags = Tag.parseTags(json.get("tags")); UserTagList userTagList = new UserTagList(userId, tags); result.add(userTagList); } return result; } }
/** Very simple way to "erase" passwords - * replaces all field values whose names contains {@code 'pass'} by {@code 'xxxxx'}. */ private static JsonNode secure(JsonNode node) { if (node.isObject()) { ObjectNode objectNode = (ObjectNode)node; Iterator<Map.Entry<String, JsonNode>> fields = node.getFields(); while (fields.hasNext()) { Map.Entry<String, JsonNode> field = fields.next(); if (field.getValue().isTextual() && field.getKey().toLowerCase().contains("pass")) { objectNode.put(field.getKey(), "xxxxx"); } else { secure(field.getValue()); } } return objectNode; } else if (node.isArray()) { ArrayNode arrayNode = (ArrayNode)node; Iterator<JsonNode> elements = arrayNode.getElements(); while (elements.hasNext()) { secure(elements.next()); } return arrayNode; } else { return node; } }
private static Object jsonNodeAsSimpleObject(JsonNode value) { Object o = null; if (value.isTextual()) { o = value.asText(); } else if (value.isArray()) { ArrayList<Object> arrayList = new ArrayList<>(); for (Iterator<JsonNode> iter = ((ArrayNode) value).getElements(); iter .hasNext();) { arrayList.add(jsonNodeAsSimpleObject(iter.next())); } o = arrayList.toArray(); } else if (value.isNull()) { o = null; } else if (value.isObject()) { HashMap<String, Object> map = new HashMap<String, Object>(); final Iterator<Entry<String, JsonNode>> fields = value.getFields(); while (fields.hasNext()) { final Entry<String, JsonNode> next = fields.next(); map.put(next.getKey(), jsonNodeAsSimpleObject(next.getValue())); } o = map; } else throw new RuntimeException("Unknown type: " + value); return o; }
private JsonNode projection(JsonNode node, String relativePath) { if (relativePath == null || relativePath.length() == 0) { return node; } if (node.isArray()) { ArrayNode arrayNode = mapper.createArrayNode(); Iterator<JsonNode> elementsIterator = ((ArrayNode) node).getElements(); while (elementsIterator.hasNext()) { ObjectNode oNode = mapper.createObjectNode(); oNode.put(lastPartOfPath(relativePath), projection(elementsIterator.next(), relativePath)); arrayNode.add(oNode); } return arrayNode; } else { int firstDotPosition = relativePath.indexOf('.'); if (firstDotPosition == -1) { return node.get(relativePath); } else { return projection(node.get(relativePath.substring(0, firstDotPosition)), relativePath.substring(firstDotPosition + 1)); } } }
private Map<String, JobConfig.Builder> getJobConfigs(ArrayNode root) throws HelixException, IOException { Map<String, JobConfig.Builder> jobConfigsMap = new HashMap<>(); for (Iterator<JsonNode> it = root.getElements(); it.hasNext(); ) { JsonNode job = it.next(); ZNRecord record = null; try { record = toZNRecord(job.toString()); } catch (IOException e) { // Ignore the parse since it could be just simple fields } if (record == null || record.getSimpleFields().isEmpty()) { Map<String, String> cfgMap = OBJECT_MAPPER.readValue(job.toString(), TypeFactory.defaultInstance() .constructMapType(HashMap.class, String.class, String.class)); jobConfigsMap .put(job.get(Properties.id.name()).getTextValue(), JobAccessor.getJobConfig(cfgMap)); } else { jobConfigsMap .put(job.get(Properties.id.name()).getTextValue(), JobAccessor.getJobConfig(record)); } } return jobConfigsMap; } }
ArrayNode child = (ArrayNode) root.get(metaType); List<JsonNode> loadList = new ArrayList<JsonNode>(); Iterator<JsonNode> instIter = child.getElements(); rawData.put(metaType, loadList); while (instIter.hasNext()) {
private void readTypeNode(ObjectNode node) throws JsonSchemaValidationException { JsonNode typeNode = node.get("type"); if (typeNode != null) { if (typeNode.isArray()) { Iterator<JsonNode> it = ((ArrayNode) typeNode).getElements(); while (it.hasNext()) { JsonNode vnode = it.next(); if (!vnode.isTextual()) { throw new JsonSchemaValidationException("Invalid type union. Item is not textual", "", typeNode, null); } addTypeValue(vnode.asText()); } } else if (typeNode.isTextual()) { addTypeValue(typeNode.asText()); } else { throw new JsonSchemaValidationException("Invalid schema - invalid object type", "", typeNode, null); } } }
if (jsonNode.isArray()) { ArrayNode array = (ArrayNode) jsonNode; Iterator<JsonNode> it = array.getElements(); value = new ArrayList<Object>(); while (it.hasNext()) {
Iterator<JsonNode> nodeIter = arrayNode.getElements(); while(nodeIter.hasNext()) { JsonNode valNode = nodeIter.next();