private static Object convert(JsonNode value) { if (value.isArray()) { List<String> retvalList = new ArrayList<>(); for (JsonNode arrayElement : value) retvalList.add(arrayElement.asText()); return retvalList; } return value.getNodeType() == JsonNodeType.NUMBER ? value.numberValue() : value.asText(); }
/** * Deserialize an AccessControlList object. * @param jsonParser the json parser * @param deserializationContext deserializationcontext * @return * @throws IOException * @throws JsonProcessingException */ @Override public AccessControlList deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); String owner = node.get(OWNER_FIELD).asText(); String owningGroup = node.get(OWNING_GROUP_FIELD).asText(); List<String> stringEntries = new ArrayList<>(); Iterator<JsonNode> nodeIterator = node.get(STRING_ENTRY_FIELD).elements(); while (nodeIterator.hasNext()) { stringEntries.add(nodeIterator.next().asText()); } return AccessControlList.fromStringEntries(owner, owningGroup, stringEntries); } }
protected List<String> getValueAsList(String name, JsonNode objectNode) { List<String> resultList = new ArrayList<String>(); JsonNode valuesNode = objectNode.get(name); if (valuesNode != null) { for (JsonNode valueNode : valuesNode) { if (valueNode.get("value") != null && !valueNode.get("value").isNull()) { resultList.add(valueNode.get("value").asText()); } } } return resultList; }
/** * Transforms the {@link JsonNode} into a map to integrate with the {@link SignatureChecker} utility. * * @param messageJson JSON of message. * @return Transformed map. */ private Map<String, String> toMap(JsonNode messageJson) { Map<String, String> fields = new HashMap<String, String>(messageJson.size()); Iterator<Map.Entry<String, JsonNode>> jsonFields = messageJson.fields(); while (jsonFields.hasNext()) { Map.Entry<String, JsonNode> next = jsonFields.next(); fields.put(next.getKey(), next.getValue().asText()); } return fields; }
public static List<String> getPropertyValueAsList(String name, JsonNode objectNode) { List<String> resultList = new ArrayList<String>(); JsonNode propertyNode = getProperty(name, objectNode); if (propertyNode != null && !"null".equalsIgnoreCase(propertyNode.asText())) { String propertyValue = propertyNode.asText(); String[] valueList = propertyValue.split(","); for (String value : valueList) { resultList.add(value.trim()); } } return resultList; }
protected List<String> getActiveValueList(List<String> originalValues, String propertyName, ObjectNode taskElementProperties) { List<String> activeValues = originalValues; if (taskElementProperties != null) { JsonNode overrideValuesNode = taskElementProperties.get(propertyName); if (overrideValuesNode != null) { if (overrideValuesNode.isNull() || !overrideValuesNode.isArray() || overrideValuesNode.size() == 0) { activeValues = null; } else { activeValues = new ArrayList<String>(); for (JsonNode valueNode : overrideValuesNode) { activeValues.add(valueNode.asText()); } } } } return activeValues; } }
Map<String, JsonNode> sourceRefMap) { if (objectNode.get(EDITOR_CHILD_SHAPES) != null) { for (JsonNode jsonChildNode : objectNode.get(EDITOR_CHILD_SHAPES)) { JsonNode targetNode = childNode.get("target"); if (targetNode != null && !targetNode.isNull()) { String targetRefId = targetNode.get(EDITOR_SHAPE_ID).asText(); List<JsonNode> sourceAndTargetList = new ArrayList<JsonNode>(); sourceAndTargetList.add(sourceRefMap.get(childNode.get(EDITOR_SHAPE_ID).asText())); sourceAndTargetList.add(shapeMap.get(targetRefId)); sourceAndTargetMap.put(childEdgeId, sourceAndTargetList);
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) { ServiceTask serviceTask = new ServiceTask(); serviceTask.setType(ServiceTask.DMN_TASK); JsonNode decisionTableReferenceNode = getProperty(PROPERTY_DECISIONTABLE_REFERENCE, elementNode); if (decisionTableReferenceNode != null && decisionTableReferenceNode.has("id") && !(decisionTableReferenceNode.get("id").isNull())) { String decisionTableId = decisionTableReferenceNode.get("id").asText(); if (decisionTableMap != null) { String decisionTableKey = decisionTableMap.get(decisionTableId); FieldExtension decisionTableKeyField = new FieldExtension(); decisionTableKeyField.setFieldName(PROPERTY_DECISIONTABLE_REFERENCE_KEY); decisionTableKeyField.setStringValue(decisionTableKey); serviceTask.getFieldExtensions().add(decisionTableKeyField); } } return serviceTask; }
@Override public Callback deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { Callback result = new Callback(); JsonNode node = jp.getCodec().readTree(jp); ObjectNode objectNode = (ObjectNode)node; Map<String, Object> extensions = new LinkedHashMap<>(); for (Iterator<String> it = objectNode.fieldNames(); it.hasNext(); ) { String childName = it.next(); JsonNode child = objectNode.get(childName); // if name start with `x-` consider it an extesion if (childName.startsWith("x-")) { extensions.put(childName, Json.mapper().convertValue(child, Object.class)); } else if (childName.equals("$ref")) { result.$ref(child.asText()); } else { result.put(childName, Json.mapper().convertValue(child, PathItem.class)); } } if (!extensions.isEmpty()) { result.setExtensions(extensions); } return result; } }
@Test public void reportSpan() throws Exception { reporter.report(mock(SpanContextInformation.class), getSpan(100)); elasticsearchClient.waitForCompletion(); refresh(); final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits"); assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1); final JsonNode spanJson = hits.get("hits").elements().next().get("_source"); assertThat(spanJson.get("type").asText()).as(spanJson.toString()).isEqualTo("jdbc"); assertThat(spanJson.get("method").asText()).as(spanJson.toString()).isEqualTo("SELECT"); assertThat(spanJson.get("db.statement")).as(spanJson.toString()).isNotNull(); assertThat(spanJson.get("db.statement").asText()).as(spanJson.toString()).isEqualTo("SELECT * from STAGEMONITOR where 1 < 2"); assertThat(spanJson.get("duration_ms").asInt()).as(spanJson.toString()).isEqualTo(100); assertThat(spanJson.get("name").asText()).as(spanJson.toString()).isEqualTo("ElasticsearchExternalSpanReporterIntegrationTest#test"); }
protected static String getActiveValue(String originalValue, String propertyName, ObjectNode elementProperties) { String activeValue = originalValue; if (elementProperties != null) { JsonNode overrideValueNode = elementProperties.get(propertyName); if (overrideValueNode != null) { if (overrideValueNode.isNull()) { activeValue = null; } else { activeValue = overrideValueNode.asText(); } } } return activeValue; }
private void addMinIntervalToPanels(ObjectNode dashboard, String interval) { for (JsonNode row : dashboard.get("rows")) { for (JsonNode panel : row.get("panels")) { if (panel.has("datasource") && panel.get("datasource").asText().equals(ES_STAGEMONITOR_DS_NAME)) { ((ObjectNode) panel).put("interval", "$Interval"); } } } for (JsonNode template : dashboard.get("templating").get("list")) { if (template.has("name") && "Interval".equals(template.get("name").asText())) { ((ObjectNode) template).put("auto_min", interval); } } }
@Test public void testParameters() { final SpanWrapper span = createTestSpan(1, s -> SpanUtils.setParameters(s, Collections.singletonMap("foo", "bar"))); final ObjectNode jsonSpan = JsonUtils.toObjectNode(span); assertThat(jsonSpan.get("parameters")).isNotNull(); assertThat(jsonSpan.get("parameters").get(0)).isNotNull(); assertThat(jsonSpan.get("parameters").get(0).get("key").asText()).isEqualTo("foo"); assertThat(jsonSpan.get("parameters").get(0).get("value").asText()).isEqualTo("bar"); }
public SegmentZKMetadataCustomMapModifier(@Nonnull String jsonString) throws IOException { JsonNode jsonNode = JsonUtils.stringToJsonNode(jsonString); _modifyMode = ModifyMode.valueOf(jsonNode.get(MAP_MODIFY_MODE_KEY).asText()); JsonNode jsonMap = jsonNode.get(MAP_KEY); if (jsonMap == null || jsonMap.size() == 0) { _map = null; } else { _map = new HashMap<>(); Iterator<String> keys = jsonMap.fieldNames(); while (keys.hasNext()) { String key = keys.next(); _map.put(key, jsonMap.get(key).asText()); } } }
private List<Stock> processNode(JsonNode node) { List<Stock> stocks = new ArrayList<>(); JsonNode data = node.get("data"); for (JsonNode jsonNode : data) { String symbol = jsonNode.get(0).asText(); String name = jsonNode.get(1).asText(); Stock stock = new Stock(name, symbol); stocks.add(stock); } return stocks; }
private static List<ShardRouting> buildShardRoutings(JsonNode shardRoutings) { final ImmutableList.Builder<ShardRouting> shardRoutingsBuilder = ImmutableList.builder(); final Iterator<Map.Entry<String, JsonNode>> it = shardRoutings.fields(); while (it.hasNext()) { final Map.Entry<String, JsonNode> entry = it.next(); final int shardId = Integer.parseInt(entry.getKey()); final JsonNode shards = entry.getValue(); final String state = routing.path("state").asText("unknown").toLowerCase(Locale.ENGLISH); final String nodeId = routing.path("node").asText("Unknown"); final String nodeHostname = null; final String relocatingNode = routing.path("relocating_node").asText(null);
@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { for (Map.Entry<String, JsonNode> entry : _children.entrySet()) { if (fieldName.equals(entry.getKey())) { if (foundSoFar == null) { foundSoFar = new ArrayList<String>(); } foundSoFar.add(entry.getValue().asText()); } else { // only add children if parent not added foundSoFar = entry.getValue().findValuesAsText(fieldName, foundSoFar); } } return foundSoFar; }
@Test public void testUpdateSpan() throws Exception { final Span span = tracer.buildSpan("Test#test") .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .start(); span.finish(); elasticsearchClient.waitForCompletion(); refresh(); reporter.updateSpan(B3HeaderFormat.getB3Identifiers(tracer, span), null, Collections.singletonMap("foo", "bar")); refresh(); final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits"); assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1); final JsonNode spanJson = hits.get("hits").elements().next().get("_source"); assertThat(spanJson.get("foo").asText()).as(spanJson.toString()).isEqualTo("bar"); }