Search in sources :

Example 96 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project java by wavefrontHQ.

the class JsonMetricsParser method processValueNode.

public static void processValueNode(JsonNode value, String table, String metric, String host, long timestamp, List<ReportPoint> points, Map<String, String> tags) {
    if (value.isNumber()) {
        if (value.isLong()) {
            points.add(makePoint(table, metric, host, value.longValue(), timestamp, tags));
        } else {
            points.add(makePoint(table, metric, host, value.doubleValue(), timestamp, tags));
        }
    } else if (value.isTextual()) {
        points.add(makePoint(table, metric, host, value.textValue(), timestamp, tags));
    } else if (value.isObject()) {
        if (/*wavefront histogram*/
        value.has("bins")) {
            Iterator<JsonNode> binIt = ((ArrayNode) value.get("bins")).elements();
            while (binIt.hasNext()) {
                JsonNode bin = binIt.next();
                List<Integer> counts = newArrayList();
                bin.get("counts").elements().forEachRemaining(v -> counts.add(v.intValue()));
                List<Double> means = newArrayList();
                bin.get("means").elements().forEachRemaining(v -> means.add(v.doubleValue()));
                points.add(makeHistogramPoint(table, metric, host, tags, bin.get("startMillis").longValue(), bin.get("durationMillis").intValue(), means, counts));
            }
        } else {
            report(table, metric, value, points, host, timestamp, tags);
        }
    } else if (value.isBoolean()) {
        points.add(makePoint(table, metric, host, value.booleanValue() ? 1.0 : 0.0, timestamp, tags));
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 97 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project iobserve-analysis by research-iobserve.

the class TBehaviorModelVisualization method createEdges.

/**
 * create new edges at visualization backend.
 *
 * @param entryCallEdges
 *            entryCallEdges
 * @param modelId
 *            modelId
 */
private void createEdges(final Set<EntryCallEdge> entryCallEdges, final long modelId) {
    final ArrayNode edges = this.objectMapper.createArrayNode();
    for (final EntryCallEdge entryCallEdge : entryCallEdges) {
        final ObjectNode json = this.objectMapper.createObjectNode();
        final String sourceSignature = entryCallEdge.getSource().getSignature();
        final String targetSignature = entryCallEdge.getTarget().getSignature();
        json.put("id", 0);
        json.put("start", this.nodeMap.get(sourceSignature));
        json.put("end", this.nodeMap.get(targetSignature));
        json.put("action", String.format("%s->%s", sourceSignature, targetSignature));
        json.put("count", entryCallEdge.getCalls());
        this.postElement(json, this.getEdgeUrl(modelId));
        edges.add(json);
    }
}
Also used : EntryCallEdge(org.iobserve.analysis.clustering.filter.models.EntryCallEdge) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 98 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project swagger-parser by swagger-api.

the class OpenAPIDeserializer method getPathItem.

public PathItem getPathItem(ObjectNode obj, String location, ParseResult result) {
    PathItem pathItem = new PathItem();
    if (obj.get("$ref") != null) {
        JsonNode ref = obj.get("$ref");
        if (ref.getNodeType().equals(JsonNodeType.STRING)) {
            String mungedRef = mungedRef(ref.textValue());
            if (mungedRef != null) {
                pathItem.set$ref(mungedRef);
            } else {
                pathItem.set$ref(ref.textValue());
            }
            return pathItem;
        } else if (ref.getNodeType().equals(JsonNodeType.OBJECT)) {
            ObjectNode node = (ObjectNode) ref;
            // extra keys
            Set<String> keys = getKeys(node);
            for (String key : keys) {
                result.extra(location, key, node.get(key));
            }
        }
        return null;
    }
    String value = getString("summary", obj, false, location, result);
    if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
        pathItem.setSummary(value);
    }
    value = getString("description", obj, false, location, result);
    if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
        pathItem.setDescription(value);
    }
    ArrayNode parameters = getArray("parameters", obj, false, location, result);
    if (parameters != null && parameters.size() > 0) {
        pathItem.setParameters(getParameterList(parameters, location, result));
    }
    ArrayNode servers = getArray("servers", obj, false, location, result);
    if (servers != null && servers.size() > 0) {
        pathItem.setServers(getServersList(servers, location, result));
    }
    ObjectNode node = getObject("get", obj, false, location, result);
    if (node != null) {
        Operation operation = getOperation(node, location + "(get)", result);
        if (operation != null) {
            pathItem.setGet(operation);
        }
    }
    node = getObject("put", obj, false, location, result);
    if (node != null) {
        Operation operation = getOperation(node, location + "(put)", result);
        if (operation != null) {
            pathItem.setPut(operation);
        }
    }
    node = getObject("post", obj, false, location, result);
    if (node != null) {
        Operation operation = getOperation(node, location + "(post)", result);
        if (operation != null) {
            pathItem.setPost(operation);
        }
    }
    node = getObject("head", obj, false, location, result);
    if (node != null) {
        Operation operation = getOperation(node, location + "(head)", result);
        if (operation != null) {
            pathItem.setHead(operation);
        }
    }
    node = getObject("delete", obj, false, location, result);
    if (node != null) {
        Operation operation = getOperation(node, location + "(delete)", result);
        if (operation != null) {
            pathItem.setDelete(operation);
        }
    }
    node = getObject("patch", obj, false, location, result);
    if (node != null) {
        Operation operation = getOperation(node, location + "(patch)", result);
        if (operation != null) {
            pathItem.setPatch(operation);
        }
    }
    node = getObject("options", obj, false, location, result);
    if (node != null) {
        Operation operation = getOperation(node, location + "(options)", result);
        if (operation != null) {
            pathItem.setOptions(operation);
        }
    }
    node = getObject("trace", obj, false, location, result);
    if (node != null) {
        Operation operation = getOperation(node, location + "(trace)", result);
        if (operation != null) {
            pathItem.setTrace(operation);
        }
    }
    Map<String, Object> extensions = getExtensions(obj);
    if (extensions != null && extensions.size() > 0) {
        pathItem.setExtensions(extensions);
    }
    Set<String> keys = getKeys(obj);
    for (String key : keys) {
        if (!PATHITEM_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, obj.get(key));
        }
    }
    return pathItem;
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Operation(io.swagger.v3.oas.models.Operation)

Example 99 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project swagger-parser by swagger-api.

the class OpenAPIDeserializer method getServerVariable.

public ServerVariable getServerVariable(ObjectNode obj, String location, ParseResult result) {
    if (obj == null) {
        return null;
    }
    ServerVariable serverVariable = new ServerVariable();
    ArrayNode arrayNode = getArray("enum", obj, false, location, result);
    if (arrayNode != null) {
        List<String> _enum = new ArrayList<>();
        for (JsonNode n : arrayNode) {
            if (n.isValueNode()) {
                _enum.add(n.asText());
                serverVariable.setEnum(_enum);
            } else {
                result.invalidType(location, "enum", "value", n);
            }
        }
    }
    String value = getString("default", obj, true, String.format("%s.%s", location, "default"), result);
    if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
        serverVariable.setDefault(value);
    }
    value = getString("description", obj, false, String.format("%s.%s", location, "description"), result);
    if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
        serverVariable.setDescription(value);
    }
    Map<String, Object> extensions = getExtensions(obj);
    if (extensions != null && extensions.size() > 0) {
        serverVariable.setExtensions(extensions);
    }
    Set<String> keys = getKeys(obj);
    for (String key : keys) {
        if (!SERVER_VARIABLE_KEYS.contains(key) && !key.startsWith("x-")) {
            result.extra(location, key, obj.get(key));
        }
    }
    return serverVariable;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ServerVariable(io.swagger.v3.oas.models.servers.ServerVariable)

Example 100 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project swagger-parser by swagger-api.

the class OpenAPIDeserializer method getArray.

public ArrayNode getArray(String key, ObjectNode node, boolean required, String location, ParseResult result) {
    JsonNode value = node.get(key);
    ArrayNode arrayNode = null;
    if (value == null) {
        if (required) {
            result.missing(location, key);
            result.invalid();
        }
    } else if (!value.getNodeType().equals(JsonNodeType.ARRAY)) {
        result.invalidType(location, key, "array", value);
    } else {
        arrayNode = (ArrayNode) value;
    }
    return arrayNode;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)979 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)542 JsonNode (com.fasterxml.jackson.databind.JsonNode)402 Test (org.junit.Test)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)125 ArrayList (java.util.ArrayList)110 IOException (java.io.IOException)93 Map (java.util.Map)74 HashMap (java.util.HashMap)68 List (java.util.List)50 TextNode (com.fasterxml.jackson.databind.node.TextNode)38 Test (org.testng.annotations.Test)35 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)30 HashSet (java.util.HashSet)30 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)25 Deployment (org.activiti.engine.test.Deployment)23 File (java.io.File)22 InputStream (java.io.InputStream)20 Iterator (java.util.Iterator)20 StringEntity (org.apache.http.entity.StringEntity)20