Example usage for com.fasterxml.jackson.databind.node ObjectNode putPOJO

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode putPOJO

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode putPOJO.

Prototype

public ObjectNode putPOJO(String paramString, Object paramObject) 

Source Link

Usage

From source file:Main.java

public static String takeDumpJSON(ThreadMXBean threadMXBean) throws IOException {
    ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true);
    List<Map<String, Object>> threads = new ArrayList<>();

    for (ThreadInfo thread : threadInfos) {
        Map<String, Object> threadMap = new HashMap<>();
        threadMap.put("name", thread.getThreadName());
        threadMap.put("id", thread.getThreadId());
        threadMap.put("state", thread.getThreadState().name());
        List<String> stacktrace = new ArrayList<>();
        for (StackTraceElement element : thread.getStackTrace()) {
            stacktrace.add(element.toString());
        }// w w w.j  a v  a 2 s  .  c  o m
        threadMap.put("stack", stacktrace);

        if (thread.getLockName() != null) {
            threadMap.put("lock_name", thread.getLockName());
        }
        if (thread.getLockOwnerId() != -1) {
            threadMap.put("lock_owner_id", thread.getLockOwnerId());
        }
        if (thread.getBlockedTime() > 0) {
            threadMap.put("blocked_time", thread.getBlockedTime());
        }
        if (thread.getBlockedCount() > 0) {
            threadMap.put("blocked_count", thread.getBlockedCount());
        }
        if (thread.getLockedMonitors().length > 0) {
            threadMap.put("locked_monitors", thread.getLockedMonitors());
        }
        if (thread.getLockedSynchronizers().length > 0) {
            threadMap.put("locked_synchronizers", thread.getLockedSynchronizers());
        }
        threads.add(threadMap);
    }
    ObjectMapper om = new ObjectMapper();
    ObjectNode json = om.createObjectNode();
    json.put("date", new Date().toString());
    json.putPOJO("threads", threads);

    long[] deadlockedThreads = threadMXBean.findDeadlockedThreads();
    long[] monitorDeadlockedThreads = threadMXBean.findMonitorDeadlockedThreads();
    if (deadlockedThreads != null && deadlockedThreads.length > 0) {
        json.putPOJO("deadlocked_thread_ids", deadlockedThreads);
    }
    if (monitorDeadlockedThreads != null && monitorDeadlockedThreads.length > 0) {
        json.putPOJO("monitor_deadlocked_thread_ids", monitorDeadlockedThreads);
    }
    om.enable(SerializationFeature.INDENT_OUTPUT);
    return om.writerWithDefaultPrettyPrinter().writeValueAsString(json);
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static JsonNode newTaskExecutionResult(TaskExecutionResult taskExecutionResult) {
    ObjectNode node = newNode();
    node.put("status", taskExecutionResult.getStatus().name().toLowerCase());
    node.put("message", taskExecutionResult.getMessage());
    node.putPOJO("resultData", taskExecutionResult.getResultData());
    node.put("subTaskRunId",
            taskExecutionResult.getSubTaskRunId().isPresent()
                    ? taskExecutionResult.getSubTaskRunId().get().getId()
                    : null);//  www. j  a  va2  s.c om
    node.put("completionTimeUtc",
            taskExecutionResult.getCompletionTimeUtc().format(DateTimeFormatter.ISO_DATE_TIME));
    return node;
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static JsonNode newTask(Task task) {
    RunnableTaskDagBuilder builder = new RunnableTaskDagBuilder(task);
    ArrayNode tasks = newArrayNode();//from w  ww .  java  2s. c om
    builder.getTasks().values().forEach(thisTask -> {
        ObjectNode node = newNode();
        node.put("taskId", thisTask.getTaskId().getId());
        node.set("taskType", thisTask.isExecutable() ? newTaskType(thisTask.getTaskType()) : null);
        node.putPOJO("metaData", thisTask.getMetaData());
        node.put("isExecutable", thisTask.isExecutable());

        List<String> childrenTaskIds = thisTask.getChildrenTasks().stream().map(t -> t.getTaskId().getId())
                .collect(Collectors.toList());
        node.putPOJO("childrenTaskIds", childrenTaskIds);

        tasks.add(node);
    });

    ObjectNode node = newNode();
    node.put("rootTaskId", task.getTaskId().getId());
    node.set("tasks", tasks);
    return node;
}

From source file:com.nirmata.workflow.details.JsonSerializer.java

public static JsonNode newExecutableTask(ExecutableTask executableTask) {
    ObjectNode node = newNode();
    node.put("runId", executableTask.getRunId().getId());
    node.put("taskId", executableTask.getTaskId().getId());
    node.set("taskType", newTaskType(executableTask.getTaskType()));
    node.putPOJO("metaData", executableTask.getMetaData());
    node.put("isExecutable", executableTask.isExecutable());
    return node;/*from w  w w.  j  a  v a2 s .c  om*/
}

From source file:com.erudika.para.utils.ValidationUtils.java

/**
 * Returns the JSON object containing all validation constraints for all the core Para classes and classes defined
 * by the given app.//from  ww w  . j a v a2s.  co  m
 *
 * @param app an app
 * @return JSON string
 */
public static String getAllValidationConstraints(App app) {
    String json = "{}";
    try {
        ObjectNode parentNode = Utils.getJsonMapper().createObjectNode();
        for (String type : RestUtils.getAllTypes(app).values()) {
            Map<?, ?> constraintsNode = getValidationConstraints(app, type);
            if (constraintsNode.size() > 0) {
                parentNode.putPOJO(StringUtils.capitalize(type), constraintsNode);
            }
        }
        json = Utils.getJsonWriter().writeValueAsString(parentNode);
    } catch (IOException ex) {
        logger.error(null, ex);
    }
    return json;
}

From source file:easyrpc.server.serialization.jsonrpc.JSONCallee.java

private static final void addResult(ObjectNode json, Object value) {
    switch (value.getClass().getName()) {
    case "java.lang.Integer":
    case "int":
        json.put("result", (Integer) value);
        break;/*from  w  w  w .ja  va 2s.  c  o m*/
    case "java.lang.Long":
    case "long":
        json.put("result", (Long) value);
        break;
    case "java.lang.Character":
    case "char":
        json.put("result", (java.lang.Character) value);
        break;
    case "java.lang.Void":
    case "void":
        throw new IllegalArgumentException("A parameter cannot be of void type");
    case "java.lang.Float":
    case "float":
        json.put("result", (Float) value);
        break;
    case "java.lang.Double":
    case "double":
        json.put("result", (Double) value);
        break;
    case "java.lang.String":
        json.put("result", (String) value);
        break;
    default:
        // map an object
        ObjectNode retPojo = json.putPOJO("result", MAPPER.valueToTree(value));
        //                    System.out.println("retPojo.toString() = " + retPojo.toString());
    }
}

From source file:org.envirocar.server.rest.encoding.json.MeasurementJSONEncoder.java

@Override
public ObjectNode encodeJSON(Measurement t, AccessRights rights, MediaType mediaType) {
    ObjectNode measurement = getJsonFactory().objectNode();
    measurement.put(GeoJSONConstants.TYPE_KEY, GeoJSONConstants.FEATURE_TYPE);
    if (t.hasGeometry() && rights.canSeeGeometryOf(t)) {
        measurement.put(JSONConstants.GEOMETRY_KEY,
                geometryEncoder.encodeJSON(t.getGeometry(), rights, mediaType));
    }/*from w ww .  j a  v  a 2 s .  c om*/

    ObjectNode properties = measurement.putObject(GeoJSONConstants.PROPERTIES_KEY);
    if (t.hasIdentifier()) {
        properties.put(JSONConstants.IDENTIFIER_KEY, t.getIdentifier());
    }
    if (t.hasTime() && rights.canSeeTimeOf(t)) {
        properties.put(JSONConstants.TIME_KEY, getDateTimeFormat().print(t.getTime()));
    }

    if (!mediaType.equals(MediaTypes.TRACK_TYPE)) {
        if (t.hasSensor() && rights.canSeeSensorOf(t)) {
            properties.put(JSONConstants.SENSOR_KEY,
                    sensorProvider.encodeJSON(t.getSensor(), rights, mediaType));
        }
        if (t.hasUser() && rights.canSeeUserOf(t)) {
            properties.put(JSONConstants.USER_KEY, userProvider.encodeJSON(t.getUser(), rights, mediaType));
        }
        if (t.hasModificationTime() && rights.canSeeModificationTimeOf(t)) {
            properties.put(JSONConstants.MODIFIED_KEY, getDateTimeFormat().print(t.getModificationTime()));
        }
        if (t.hasCreationTime() && rights.canSeeCreationTimeOf(t)) {
            properties.put(JSONConstants.CREATED_KEY, getDateTimeFormat().print(t.getCreationTime()));
        }
        if (t.hasTrack() && rights.canSeeTracks()) {
            properties.put(JSONConstants.TRACK_KEY, t.getTrack().getIdentifier());
        }
    }
    if (mediaType.equals(MediaTypes.MEASUREMENT_TYPE) || mediaType.equals(MediaTypes.MEASUREMENTS_TYPE)
            || mediaType.equals(MediaTypes.TRACK_TYPE)) {
        if (rights.canSeeValuesOf(t)) {
            ObjectNode values = properties.putObject(JSONConstants.PHENOMENONS_KEY);

            for (MeasurementValue mv : t.getValues()) {
                if (mv.hasPhenomenon() && mv.hasValue()) {
                    ObjectNode phenomenon = values.objectNode();
                    phenomenon.putPOJO(JSONConstants.VALUE_KEY, mv.getValue());
                    values.put(mv.getPhenomenon().getName(), phenomenon);
                    if (mv.getPhenomenon().hasUnit()) {
                        phenomenon.put(JSONConstants.UNIT_KEY, mv.getPhenomenon().getUnit());
                    }
                }
            }
        }
    }
    return measurement;
}

From source file:com.ning.metrics.serialization.event.SmileEnvelopeEvent.java

private static void addToTree(ObjectNode root, String name, Object value) {
    /* could wrap everything as POJONode, but that's bit inefficient;
     * so let's handle some known cases.
     * (in reality, I doubt there could ever be non-scalars, FWIW, since
     * downstream systems expect simple key/value data)
     *///from   www. j  av  a  2s . c  om
    if (value instanceof String) {
        root.put(name, (String) value);
        return;
    }
    if (value instanceof Number) {
        Number num = (Number) value;
        if (value instanceof Integer) {
            root.put(name, num.intValue());
        } else if (value instanceof Long) {
            root.put(name, num.longValue());
        } else if (value instanceof Double) {
            root.put(name, num.doubleValue());
        } else {
            root.putPOJO(name, num);
        }
    } else if (value == Boolean.TRUE) {
        root.put(name, true);
    } else if (value == Boolean.FALSE) {
        root.put(name, false);
    } else { // most likely Date
        root.putPOJO(name, value);
    }
}

From source file:org.apache.taverna.examples.JsonExport.java

private JsonNode toJson(Profile profile) {
    ObjectNode pf = mapper.createObjectNode();

    pf.putPOJO("id", uriTools.relativeUriForBean(profile, profile.getParent()));
    // TODO: Activities and configurations
    return pf;//from  w  w  w  .  j  av  a  2s  . c  o  m
}

From source file:org.apache.taverna.examples.JsonExport.java

protected JsonNode toJson(DataLink link) {
    ObjectNode l = mapper.createObjectNode();
    l.putPOJO("receivesFrom",
            uriTools.relativeUriForBean(link.getReceivesFrom(), link.getParent().getParent()));
    l.putPOJO("sendsTo", uriTools.relativeUriForBean(link.getSendsTo(), link.getParent().getParent()));
    if (link.getMergePosition() != null) {
        l.put("mergePosition", link.getMergePosition());
    }//w  ww .  j  a v a  2s. com
    return l;
}