Search in sources :

Example 51 with ArrayNode

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

the class ABinary method toJSON.

@Override
public ObjectNode toJSON() {
    ObjectMapper om = new ObjectMapper();
    ObjectNode json = om.createObjectNode();
    int start = getStart();
    ArrayNode byteArray = om.createArrayNode();
    for (int i = 0; i < getLength(); i++) {
        byteArray.add(bytes[start + i]);
    }
    json.set("ABinary", byteArray);
    return json;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 52 with ArrayNode

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

the class PropertyDeserializer method getEnum.

private static List<String> getEnum(JsonNode node, PropertyBuilder.PropertyId type) {
    final List<String> result = new ArrayList<String>();
    JsonNode detailNode = getDetailNode(node, type);
    if (detailNode != null) {
        ArrayNode an = (ArrayNode) detailNode;
        for (JsonNode child : an) {
            if (child instanceof TextNode || child instanceof NumericNode || child instanceof IntNode || child instanceof LongNode || child instanceof DoubleNode || child instanceof FloatNode) {
                result.add(child.asText());
            }
        }
    }
    return result.isEmpty() ? null : result;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ArrayList(java.util.ArrayList) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode)

Example 53 with ArrayNode

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

the class PropertyDeserializer method getRequired.

private static List<String> getRequired(JsonNode node, PropertyBuilder.PropertyId type) {
    List<String> result = new ArrayList<String>();
    final JsonNode detailNode = getDetailNode(node, type);
    if (detailNode == null) {
        return result;
    }
    if (detailNode.isArray()) {
        ArrayNode arrayNode = (ArrayNode) detailNode;
        Iterator<JsonNode> fieldNameIter = arrayNode.iterator();
        while (fieldNameIter.hasNext()) {
            JsonNode item = fieldNameIter.next();
            result.add(item.asText());
        }
        return result;
    } else {
        throw new RuntimeException("Required property should be a list");
    }
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 54 with ArrayNode

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

the class RealmListNYTimesMultimediumDeserializer method deserialize.

@Override
public List<NYTimesMultimedium> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    RealmList<NYTimesMultimedium> list = new RealmList<>();
    TreeNode treeNode = jp.getCodec().readTree(jp);
    if (!(treeNode instanceof ArrayNode)) {
        return list;
    }
    ArrayNode arrayNode = (ArrayNode) treeNode;
    for (JsonNode node : arrayNode) {
        NYTimesMultimedium nyTimesMultimedium = objectMapper.treeToValue(node, NYTimesMultimedium.class);
        list.add(nyTimesMultimedium);
    }
    return list;
}
Also used : RealmList(io.realm.RealmList) TreeNode(com.fasterxml.jackson.core.TreeNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) NYTimesMultimedium(io.realm.examples.newsreader.model.entity.NYTimesMultimedium) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 55 with ArrayNode

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

the class JobDetailsHandlerTest method compareJobDetails.

private static void compareJobDetails(AccessExecutionGraph originalJob, String json) throws IOException {
    JsonNode result = ArchivedJobGenerationUtils.mapper.readTree(json);
    Assert.assertEquals(originalJob.getJobID().toString(), result.get("jid").asText());
    Assert.assertEquals(originalJob.getJobName(), result.get("name").asText());
    Assert.assertEquals(originalJob.isStoppable(), result.get("isStoppable").asBoolean());
    Assert.assertEquals(originalJob.getState().name(), result.get("state").asText());
    Assert.assertEquals(originalJob.getStatusTimestamp(JobStatus.CREATED), result.get("start-time").asLong());
    Assert.assertEquals(originalJob.getStatusTimestamp(originalJob.getState()), result.get("end-time").asLong());
    Assert.assertEquals(originalJob.getStatusTimestamp(originalJob.getState()) - originalJob.getStatusTimestamp(JobStatus.CREATED), result.get("duration").asLong());
    JsonNode timestamps = result.get("timestamps");
    for (JobStatus status : JobStatus.values()) {
        Assert.assertEquals(originalJob.getStatusTimestamp(status), timestamps.get(status.name()).asLong());
    }
    ArrayNode tasks = (ArrayNode) result.get("vertices");
    int x = 0;
    for (AccessExecutionJobVertex expectedTask : originalJob.getVerticesTopologically()) {
        JsonNode task = tasks.get(x);
        Assert.assertEquals(expectedTask.getJobVertexId().toString(), task.get("id").asText());
        Assert.assertEquals(expectedTask.getName(), task.get("name").asText());
        Assert.assertEquals(expectedTask.getParallelism(), task.get("parallelism").asInt());
        Assert.assertEquals(expectedTask.getAggregateState().name(), task.get("status").asText());
        Assert.assertEquals(3, task.get("start-time").asLong());
        Assert.assertEquals(5, task.get("end-time").asLong());
        Assert.assertEquals(2, task.get("duration").asLong());
        JsonNode subtasksPerState = task.get("tasks");
        Assert.assertEquals(0, subtasksPerState.get(ExecutionState.CREATED.name()).asInt());
        Assert.assertEquals(0, subtasksPerState.get(ExecutionState.SCHEDULED.name()).asInt());
        Assert.assertEquals(0, subtasksPerState.get(ExecutionState.DEPLOYING.name()).asInt());
        Assert.assertEquals(0, subtasksPerState.get(ExecutionState.RUNNING.name()).asInt());
        Assert.assertEquals(1, subtasksPerState.get(ExecutionState.FINISHED.name()).asInt());
        Assert.assertEquals(0, subtasksPerState.get(ExecutionState.CANCELING.name()).asInt());
        Assert.assertEquals(0, subtasksPerState.get(ExecutionState.CANCELED.name()).asInt());
        Assert.assertEquals(0, subtasksPerState.get(ExecutionState.FAILED.name()).asInt());
        long expectedNumBytesIn = 0;
        long expectedNumBytesOut = 0;
        long expectedNumRecordsIn = 0;
        long expectedNumRecordsOut = 0;
        for (AccessExecutionVertex vertex : expectedTask.getTaskVertices()) {
            IOMetrics ioMetrics = vertex.getCurrentExecutionAttempt().getIOMetrics();
            expectedNumBytesIn += ioMetrics.getNumBytesInLocal() + ioMetrics.getNumBytesInRemote();
            expectedNumBytesOut += ioMetrics.getNumBytesOut();
            expectedNumRecordsIn += ioMetrics.getNumRecordsIn();
            expectedNumRecordsOut += ioMetrics.getNumRecordsOut();
        }
        JsonNode metrics = task.get("metrics");
        Assert.assertEquals(expectedNumBytesIn, metrics.get("read-bytes").asLong());
        Assert.assertEquals(expectedNumBytesOut, metrics.get("write-bytes").asLong());
        Assert.assertEquals(expectedNumRecordsIn, metrics.get("read-records").asLong());
        Assert.assertEquals(expectedNumRecordsOut, metrics.get("write-records").asLong());
        x++;
    }
    Assert.assertEquals(1, tasks.size());
    JsonNode statusCounts = result.get("status-counts");
    Assert.assertEquals(0, statusCounts.get(ExecutionState.CREATED.name()).asInt());
    Assert.assertEquals(0, statusCounts.get(ExecutionState.SCHEDULED.name()).asInt());
    Assert.assertEquals(0, statusCounts.get(ExecutionState.DEPLOYING.name()).asInt());
    Assert.assertEquals(1, statusCounts.get(ExecutionState.RUNNING.name()).asInt());
    Assert.assertEquals(0, statusCounts.get(ExecutionState.FINISHED.name()).asInt());
    Assert.assertEquals(0, statusCounts.get(ExecutionState.CANCELING.name()).asInt());
    Assert.assertEquals(0, statusCounts.get(ExecutionState.CANCELED.name()).asInt());
    Assert.assertEquals(0, statusCounts.get(ExecutionState.FAILED.name()).asInt());
    Assert.assertEquals(ArchivedJobGenerationUtils.mapper.readTree(originalJob.getJsonPlan()), result.get("plan"));
}
Also used : JobStatus(org.apache.flink.runtime.jobgraph.JobStatus) AccessExecutionJobVertex(org.apache.flink.runtime.executiongraph.AccessExecutionJobVertex) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOMetrics(org.apache.flink.runtime.executiongraph.IOMetrics) AccessExecutionVertex(org.apache.flink.runtime.executiongraph.AccessExecutionVertex)

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