List of usage examples for com.fasterxml.jackson.databind JsonNode elements
public Iterator<JsonNode> elements()
From source file:com.hortonworks.pso.data.generator.fields.StringField.java
public StringField(JsonNode node) { super(node);/*from w w w .j av a2 s .co m*/ if (node.has("random")) { JsonNode rNode = node.get("random"); if (rNode.get("min") != null) min = rNode.get("min").asInt(); if (rNode.get("max") != null) max = rNode.get("max").asInt(); if (min < max) diff = Math.abs(max - min); if (rNode.get("chars") != null) { charStr = rNode.get("chars").asText(); } if (rNode.get("pool") != null) { // size is required poolSize = rNode.get("pool").get("size").asInt(); fillPool(); } } else if (node.has("set")) { JsonNode setNode = node.get("set"); type = TYPE.SET; set = new String[setNode.size()]; int i = 0; for (Iterator<JsonNode> it = setNode.elements(); it.hasNext();) { JsonNode element = it.next(); set[i++] = element.asText(); } } }
From source file:de.tudarmstadt.ukp.dkpro.wsd.wsi.si.InducedSenseInventory.java
/** * Loads a serialized sense inventory from a json file * * @param fileName/*from w ww . j a va2 s . c o m*/ * @throws WSDException */ public void loadInventory(String fileName) throws WSDException { ObjectMapper mapper = new ObjectMapper(); try { BufferedReader fileReader = new BufferedReader(new FileReader(fileName)); JsonNode root = mapper.readTree(fileReader); Iterator<JsonNode> it = root.elements(); while (it.hasNext()) { JsonNode termNode = it.next(); if (termNode.has("term")) { String term = termNode.get("term").textValue(); Iterator<JsonNode> it2 = termNode.get("clusters").elements(); int senseIndex = 0; while (it2.hasNext()) { String senseId = term + "_" + senseIndex++; JsonNode clusterNode = it2.next(); Iterator<JsonNode> it3 = clusterNode.elements(); Collection<String> cluster = new LinkedList<String>(); while (it3.hasNext()) { Iterator<JsonNode> it4 = it3.next().elements(); while (it4.hasNext()) { JsonNode wordNode = it4.next(); cluster.add(wordNode.textValue()); } } addSense(term, senseId, cluster); } } } System.out.println("loaded " + inventory.size() + " terms and " + clusters.size() + " sense clusters"); } catch (Exception e) { throw new WSDException(e); } }
From source file:com.googlecode.jsonschema2pojo.rules.EnumRule.java
private void addEnumConstants(JsonNode node, JDefinedClass _enum) { for (Iterator<JsonNode> values = node.elements(); values.hasNext();) { JsonNode value = values.next();//from w ww . jav a 2 s. com if (!value.isNull()) { JEnumConstant constant = _enum.enumConstant(getConstantName(value.asText())); constant.arg(JExpr.lit(value.asText())); } } }
From source file:org.pac4j.oauth.profile.JsonList.java
@Override protected void buildFromJson(final JsonNode json) { if (json != null) { final Iterator<JsonNode> jsonIterator = json.elements(); while (jsonIterator.hasNext()) { final JsonNode node = jsonIterator.next(); buildSingleNode(node);//w w w. j ava 2 s.c o m } } }
From source file:io.progix.dropwizard.patch.explicit.PatchInstructionDeserializer.java
/** * This method is responsible for deserialization of a {@link PatchInstruction} * <p/>/* www. jav a 2s.com*/ * The value in a patch instruction is mapped to a TreeMap and can be later converted to a class of choice using * {@link JsonPatchValue} * * @see JsonDeserializer */ @Override public PatchInstruction deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { untypedObjectDeserializer.resolve(ctxt); JsonNode node = jp.getCodec().readTree(jp); PatchOperation operation = PatchOperation.valueOf(node.get("op").asText().toUpperCase()); String path = node.get("path").asText(); String from = null; JsonNode fromNode = node.get("from"); if (fromNode != null) { from = fromNode.asText(); } List<Object> values = null; JsonNode valueNode = node.get("value"); if (valueNode != null) { values = new ArrayList<>(); if (valueNode.isArray()) { Iterator<JsonNode> iterator = valueNode.elements(); while (iterator.hasNext()) { JsonNode elementNode = iterator.next(); JsonParser p = elementNode.traverse(); if (!p.hasCurrentToken()) { p.nextToken(); } Object element = untypedObjectDeserializer.deserialize(p, ctxt); values.add(element); } } else { JsonParser p = valueNode.traverse(); if (!p.hasCurrentToken()) { p.nextToken(); } Object value = untypedObjectDeserializer.deserialize(p, ctxt); values.add(value); } } return new PatchInstruction(operation, path, values, from); }
From source file:com.hortonworks.pso.data.generator.fields.StartStopFields.java
public StartStopFields(JsonNode node) { fields[0] = new StartField(); fields[1] = new StopField(); // Field Order if (node.has("order")) { // Will be a set of int. JsonNode setNode = node.get("order"); int i = 0; for (Iterator<JsonNode> it = setNode.elements(); it.hasNext();) { JsonNode element = it.next(); fields[i++].setOrder(element.asInt()); }//from ww w.java2 s . c o m } // Date Range if (node.has("format")) { format = node.get("format").asText(); System.out.println("Date Format Set: " + format); } if (df == null) { df = new SimpleDateFormat(format); } try { if (node.has("range")) { JsonNode rangeNode = node.get("range"); if (rangeNode.has("min")) { String minDtStr = rangeNode.get("min").asText(); minDt = df.parse(minDtStr); System.out.println("Min Date: " + minDt.toString()); min = minDt.getTime(); } if (rangeNode.has("max")) { String maxDtStr = rangeNode.get("max").asText(); maxDt = df.parse(maxDtStr); System.out.println("Max Date: " + maxDt.toString()); max = maxDt.getTime(); } } } catch (ParseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } // Spread min and max if (node.has("spread")) { JsonNode spread = node.get("spread"); spreadMin = spread.get("min").asLong(); spreadMax = spread.get("max").asLong(); } reset(); }
From source file:org.activiti.editor.language.json.converter.UserTaskJsonConverter.java
@Override protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) { UserTask task = new UserTask(); task.setPriority(getPropertyValueAsString(PROPERTY_PRIORITY, elementNode)); task.setFormKey(getPropertyValueAsString(PROPERTY_FORMKEY, elementNode)); task.setDueDate(getPropertyValueAsString(PROPERTY_DUEDATE, elementNode)); task.setCategory(getPropertyValueAsString(PROPERTY_CATEGORY, elementNode)); JsonNode assignmentNode = getProperty(PROPERTY_USERTASK_ASSIGNMENT, elementNode); if (assignmentNode != null) { JsonNode itemsNode = assignmentNode.get(EDITOR_PROPERTIES_GENERAL_ITEMS); if (itemsNode != null) { Iterator<JsonNode> assignmentIterator = itemsNode.elements(); while (assignmentIterator.hasNext()) { JsonNode assignmentItemNode = assignmentIterator.next(); if (assignmentItemNode.get(PROPERTY_USERTASK_ASSIGNMENT_TYPE) != null && assignmentItemNode.get(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION) != null) { String assignmentType = assignmentItemNode.get(PROPERTY_USERTASK_ASSIGNMENT_TYPE).asText(); if (PROPERTY_USERTASK_ASSIGNEE.equals(assignmentType)) { task.setAssignee( assignmentItemNode.get(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION).asText()); } else if (PROPERTY_USERTASK_CANDIDATE_USERS.equals(assignmentType)) { task.setCandidateUsers( getValueAsList(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION, assignmentItemNode)); } else if (PROPERTY_USERTASK_CANDIDATE_GROUPS.equals(assignmentType)) { task.setCandidateGroups( getValueAsList(PROPERTY_USERTASK_ASSIGNMENT_EXPRESSION, assignmentItemNode)); }/* ww w.j av a 2s .co m*/ } } } } convertJsonToFormProperties(elementNode, task); return task; }
From source file:utils.SampleData.java
public static JsonNode secureSampleData(JsonNode sample) { String[] nameArray = new String[] { "member_sk", "membersk", "member_id", "memberid", "mem_sk", "mem_id" }; if (sample != null && sample.has("sample")) { JsonNode sampleNode = sample.get("sample"); if (sampleNode != null && sampleNode.has("columnNames") && sampleNode.has("data")) { JsonNode namesNode = sampleNode.get("columnNames"); JsonNode dataNode = sampleNode.get("data"); if (namesNode != null && namesNode.isArray()) { for (int i = 0; i < namesNode.size(); i++) { if (Arrays.asList(nameArray).contains(namesNode.get(i).asText().toLowerCase())) { if (dataNode != null && dataNode.isArray()) { for (JsonNode node : dataNode) { JsonNode valueNode = node.get(i); ((ArrayNode) node).set(i, new TextNode("********")); }/*from w w w . ja v a2s. c o m*/ } } } } } else { int index = 0; Iterator<JsonNode> arrayIterator = sampleNode.elements(); while (arrayIterator.hasNext()) { JsonNode sampleRowNode = arrayIterator.next(); if (sampleRowNode != null) { if (sampleRowNode.has(MEMBER_ID)) { ((ObjectNode) sampleRowNode).set(MEMBER_ID, new TextNode("********")); } if (sampleRowNode.has(TREE_ID)) { JsonNode treeIdNode = sampleRowNode.get(TREE_ID); String convertedValue = convertToHexString(treeIdNode); ((ObjectNode) sampleRowNode).set(TREE_ID, new TextNode(convertedValue)); } if (sampleRowNode.has(TRACKING_ID)) { JsonNode trackingIdNode = sampleRowNode.get(TRACKING_ID); String convertedValue = convertToHexString(trackingIdNode); ((ObjectNode) sampleRowNode).set(TRACKING_ID, new TextNode(convertedValue)); } if (sampleRowNode.has(IP_AS_BYTES)) { JsonNode ipNode = sampleRowNode.get(IP_AS_BYTES); String convertedValue = convertToHexString(ipNode); ((ObjectNode) sampleRowNode).set(IP_AS_BYTES, new TextNode(convertedValue)); } if (sampleRowNode.has(IP_AS_BYTES_1)) { JsonNode ipNode = sampleRowNode.get(IP_AS_BYTES_1); String convertedValue = convertToHexString(ipNode); ((ObjectNode) sampleRowNode).set(IP_AS_BYTES_1, new TextNode(convertedValue)); } if (sampleRowNode.has(ATTACHMENTS)) { JsonNode attachmentNode = sampleRowNode.get(ATTACHMENTS); if (attachmentNode.has(PAYLOAD)) { JsonNode payloadNode = attachmentNode.get(PAYLOAD); String value = "** " + Integer.toString(payloadNode.size()) + " bytes binary data **"; ((ObjectNode) attachmentNode).set(PAYLOAD, new TextNode(value)); } } if (sampleRowNode.has(MEDIA)) { JsonNode mediaNode = sampleRowNode.get(MEDIA); String convertedValue = convertToHexString(mediaNode); ((ObjectNode) sampleRowNode).set(MEDIA, new TextNode(convertedValue)); } if (sampleRowNode.has(HEADER)) { JsonNode headerNode = sampleRowNode.get(HEADER); if (headerNode != null) { if (headerNode.has(MEMBER_ID)) { ((ObjectNode) headerNode).set(MEMBER_ID, new TextNode("********")); } if (headerNode.has(GUID)) { JsonNode guidNode = headerNode.get(GUID); String convertedValue = convertToHexString(guidNode); ((ObjectNode) headerNode).set(GUID, new TextNode(convertedValue)); } if (headerNode.has(TREE_ID)) { JsonNode headerTreeIdNode = headerNode.get(TREE_ID); String convertedValue = convertToHexString(headerTreeIdNode); ((ObjectNode) headerNode).set(TREE_ID, new TextNode(convertedValue)); } if (headerNode.has(AUDITHEADER)) { JsonNode auditHeaderNode = headerNode.get(AUDITHEADER); if (auditHeaderNode != null && auditHeaderNode.has(MESSAGE_ID)) { JsonNode messageIdNode = auditHeaderNode.get(MESSAGE_ID); String convertedValue = convertToHexString(messageIdNode); ((ObjectNode) auditHeaderNode).set(MESSAGE_ID, new TextNode(convertedValue)); } } } } if (sampleRowNode.has(REQUEST)) { JsonNode requestNode = sampleRowNode.get(REQUEST); if (requestNode != null && requestNode.has(ATTACHMENTS)) { JsonNode attachmentsNode = requestNode.get(ATTACHMENTS); if (attachmentsNode != null && attachmentsNode.has(PAYLOAD)) { JsonNode payloadNode = attachmentsNode.get(PAYLOAD); String value = "** " + Integer.toString(payloadNode.size()) + " bytes binary data **"; ((ObjectNode) attachmentsNode).set(PAYLOAD, new TextNode(value)); } } } if (sampleRowNode.has(REQUEST_HEADER)) { JsonNode requestHeaderNode = sampleRowNode.get(REQUEST_HEADER); if (requestHeaderNode != null && requestHeaderNode.has(IP_AS_BYTES)) { JsonNode ipNode = requestHeaderNode.get(IP_AS_BYTES); String convertedValue = convertToHexString(ipNode); ((ObjectNode) requestHeaderNode).set(IP_AS_BYTES, new TextNode(convertedValue)); } if (requestHeaderNode != null && requestHeaderNode.has(IP_AS_BYTES_1)) { JsonNode ipNode = requestHeaderNode.get(IP_AS_BYTES_1); String convertedValue = convertToHexString(ipNode); ((ObjectNode) requestHeaderNode).set(IP_AS_BYTES_1, new TextNode(convertedValue)); } } } } } } return sample; }
From source file:cloudfoundry.norouter.f5.client.AbstractIControlClient.java
@Override public Collection<Pool> getAllPools(boolean fetchPoolMembers) { final String uri = POOL_URI + (fetchPoolMembers ? EXPAND_SUBCOLLECTIONS : ""); final JsonNode resource = getResource(uri); final JsonNode items = resource.get("items"); final Collection<Pool> pools = new ArrayList<>(); items.elements().forEachRemaining(node -> pools.add(readValue(node, Pool.class))); return pools; }
From source file:com.spankingrpgs.scarletmoon.loader.ItemLoader.java
private List<String> hydrateEquipSlots(JsonNode equipSlots) { if (equipSlots == null) { return Collections.emptyList(); }//from w w w .ja v a2 s . com List<String> equipSlotNames = new ArrayList<>(); Iterator<JsonNode> equipSlotsIterator = equipSlots.elements(); while (equipSlotsIterator.hasNext()) { equipSlotNames .add(EnumUtils.nameToEnum(Collections.singleton(equipSlotsIterator.next().asText())).get(0)); } return equipSlotNames; }