Java Code Examples for com.fasterxml.jackson.databind.node.ObjectNode#putPOJO()

The following examples show how to use com.fasterxml.jackson.databind.node.ObjectNode#putPOJO() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToJson.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
protected ObjectNode toJson(Port port) {
	ObjectNode p = mapper.createObjectNode();
	p.put("name", port.getName());
	p.putPOJO("id",
			uriTools.relativeUriForBean(port, scufl2Tools.findParent(
					WorkflowBundle.class, ((Child<?>) port))));

	if (port instanceof DepthPort) {
		DepthPort depthPort = (DepthPort) port;
		if (depthPort.getDepth() != null) {
			p.put("depth", depthPort.getDepth());
		}
	}
	if (port instanceof GranularDepthPort) {
		GranularDepthPort granularDepthPort = (GranularDepthPort) port;
		if (granularDepthPort.getGranularDepth() != null
				&& !granularDepthPort.getGranularDepth().equals(
						granularDepthPort.getDepth())) {
			p.put("granularDepth", granularDepthPort.getGranularDepth());
		}
	}
	p.putAll(annotations((Child<?>) port));
	return p;
}
 
Example 2
Source File: JsonExport.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
protected ObjectNode toJson(Port port) {
   ObjectNode p = mapper.createObjectNode();
   p.put("name", port.getName());
   p.putPOJO("id", uriTools.relativeUriForBean(port, 
           scufl2Tools.findParent(WorkflowBundle.class, ((Child<?>)port))));
   
   if (port instanceof DepthPort) {
    DepthPort depthPort = (DepthPort) port;
    if (depthPort.getDepth() != null) {
        p.put("depth", depthPort.getDepth());
    }
   }
   if (port instanceof GranularDepthPort) {
       GranularDepthPort granularDepthPort = (GranularDepthPort) port;
       if (granularDepthPort.getGranularDepth() != null && 
               ! granularDepthPort.getGranularDepth().equals(granularDepthPort.getDepth())) {
           p.put("granularDepth", granularDepthPort.getGranularDepth());
       }
   }
   p.putAll(annotations((Child<?>)port));
   return p;
}
 
Example 3
Source File: ToJson.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
protected JsonNode toJson(Processor proc) {
	ObjectNode p = mapper.createObjectNode();
	p.putPOJO("id",
			uriTools.relativeUriForBean(proc, proc.getParent().getParent()));
	p.put("name", proc.getName());
	addPorts(proc, p);
	p.putAll(annotations(proc));

	List<Workflow> nested = scufl2Tools.nestedWorkflowsForProcessor(proc,
			proc.getParent().getParent().getMainProfile());
	if (!nested.isEmpty()) {
		if (nested.size() == 1) {
			p.put("nestedWorkflow", toJson(nested.iterator().next()));
		} else {
			ArrayNode list = mapper.createArrayNode();
			for (Workflow w : nested) {
				list.add(toJson(w));
			}
			p.put("nestedWorkflow", list);
		}
	}
	return p;
}
 
Example 4
Source File: Pods.java    From symja_android_library with GNU General Public License v3.0 6 votes vote down vote up
/** package private */
static void addSymjaPod(ArrayNode podsArray, IExpr inExpr, IExpr outExpr, String title, String scanner, int formats,
		EvalEngine engine) {
	ArrayNode temp = JSON_OBJECT_MAPPER.createArrayNode();
	ObjectNode subpodsResult = JSON_OBJECT_MAPPER.createObjectNode();
	subpodsResult.put("title", title);
	subpodsResult.put("scanner", scanner);
	subpodsResult.put("error", "false");
	subpodsResult.put("numsubpods", 1);
	subpodsResult.putPOJO("subpods", temp);
	podsArray.add(subpodsResult);

	ObjectNode node = JSON_OBJECT_MAPPER.createObjectNode();
	temp.add(node);
	createJSONFormat(node, engine, StringFunctions.inputForm(inExpr), outExpr, formats);
}
 
Example 5
Source File: JsonReceiveMessageHandler.java    From signal-cli with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
    ObjectNode result = jsonProcessor.createObjectNode();
    if (exception != null) {
        result.putPOJO("error", new JsonError(exception));
    }
    if (envelope != null) {
        result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content));
    }
    try {
        jsonProcessor.writeValue(System.out, result);
        System.out.println();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: Metrics.java    From Geyser with MIT License 6 votes vote down vote up
@Override
protected ObjectNode getChartData() throws Exception {
    ObjectNode data = mapper.createObjectNode();
    ObjectNode values = mapper.createObjectNode();
    Map<String, Integer> map = callable.call();
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        ArrayNode categoryValues = mapper.createArrayNode();
        categoryValues.add(entry.getValue());
        values.putPOJO(entry.getKey(), categoryValues);
    }
    data.putPOJO("values", values);
    return data;
}
 
Example 7
Source File: Metrics.java    From Geyser with MIT License 6 votes vote down vote up
@Override
protected ObjectNode getChartData() throws Exception {
    ObjectNode data = mapper.createObjectNode();
    ObjectNode values = mapper.createObjectNode();
    Map<String, Integer> map = callable.call();
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean allSkipped = true;
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        if (entry.getValue() == 0) {
            continue; // Skip this invalid
        }
        allSkipped = false;
        values.put(entry.getKey(), entry.getValue());
    }
    if (allSkipped) {
        // Null = skip the chart
        return null;
    }
    data.putPOJO("values", values);
    return data;
}
 
Example 8
Source File: Metrics.java    From Geyser with MIT License 6 votes vote down vote up
private ObjectNode getRequestJsonNode() {
    ObjectNode chart = new ObjectMapper().createObjectNode();
    chart.put("chartId", chartId);
    try {
        ObjectNode data = getChartData();
        if (data == null) {
            // If the data is null we don't send the chart.
            return null;
        }
        chart.putPOJO("data", data);
    } catch (Throwable t) {
        if (logFailedRequests) {
            logger.log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
        }
        return null;
    }
    return chart;
}
 
Example 9
Source File: Metrics.java    From Geyser with MIT License 5 votes vote down vote up
@Override
protected ObjectNode getChartData() throws Exception {
    ObjectNode data = mapper.createObjectNode();
    ObjectNode values = mapper.createObjectNode();
    Map<String, int[]> map = callable.call();
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean allSkipped = true;
    for (Map.Entry<String, int[]> entry : map.entrySet()) {
        if (entry.getValue().length == 0) {
            continue; // Skip this invalid
        }
        allSkipped = false;
        ArrayNode categoryValues = mapper.createArrayNode();
        for (int categoryValue : entry.getValue()) {
            categoryValues.add(categoryValue);
        }
        values.putPOJO(entry.getKey(), categoryValues);
    }
    if (allSkipped) {
        // Null = skip the chart
        return null;
    }
    data.putPOJO("values", values);
    return data;
}
 
Example 10
Source File: JsonExport.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
private JsonNode toJson(Profile profile) {
    ObjectNode pf = mapper.createObjectNode();

    pf.putPOJO("id", uriTools.relativeUriForBean(profile, profile.getParent()));
    // TODO: Activities and configurations
    return pf;
}
 
Example 11
Source File: Metrics.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public ObjectNode getChartData() throws Exception {
    ObjectNode data = mapper.createObjectNode();
    ObjectNode values = mapper.createObjectNode();
    Map<String, Map<String, Integer>> map = callable.call();
    if (map == null || map.isEmpty()) {
        // Null = skip the chart
        return null;
    }
    boolean reallyAllSkipped = true;
    for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
        ObjectNode value = mapper.createObjectNode();
        boolean allSkipped = true;
        for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
            value.put(valueEntry.getKey(), valueEntry.getValue());
            allSkipped = false;
        }
        if (!allSkipped) {
            reallyAllSkipped = false;
            values.putPOJO(entryValues.getKey(), value);
        }
    }
    if (reallyAllSkipped) {
        // Null = skip the chart
        return null;
    }
    data.putPOJO("values", values);
    return data;
}
 
Example 12
Source File: JsonExport.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
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());
    }
    return l;
}
 
Example 13
Source File: ToJson.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
protected JsonNode toJson(ControlLink link) {
	ObjectNode l = mapper.createObjectNode();
	if (link instanceof BlockingControlLink) {
		BlockingControlLink controlLink = (BlockingControlLink) link;
		l.putPOJO("block", uriTools.relativeUriForBean(
				controlLink.getBlock(), link.getParent().getParent()));
		l.putPOJO("untilFinished", uriTools.relativeUriForBean(controlLink
				.getUntilFinished(), link.getParent().getParent()));
	}
	return l;
}
 
Example 14
Source File: TupleToJsonStringConverter.java    From event-store-demo with GNU General Public License v3.0 5 votes vote down vote up
private ObjectNode toObjectNode(Tuple source) {
    ObjectNode root = mapper.createObjectNode();
    for (int i = 0; i < source.size(); i++) {
        Object value = source.getValues().get(i);
        String name = source.getFieldNames().get(i);
        if (value == null) {
            root.putNull(name);
        } else {
            root.putPOJO(name, toNode(value));
        }
    }
    return root;
}
 
Example 15
Source File: RadioBoxGenerator.java    From sf-java-ui with MIT License 5 votes vote down vote up
@Override
public void generate(ObjectNode fieldFormDefinition, Field field) {

	RadioBox annotation = field.getAnnotation(RadioBox.class);
	fieldFormDefinition.put("key", field.getName());
	fieldFormDefinition.put("readOnly", annotation.readOnly());
	fieldFormDefinition.put("type", "radios");
	fieldFormDefinition.put("required", annotation.required());

	JsonNode radioFieldFormDefinition = fieldFormDefinition;

	ObjectMapper radioMapper = new ObjectMapper();

	ArrayNode titlesMap = radioMapper.createArrayNode();

	Map<String, String> map;

	try {
		map = (annotation.titleMap()).newInstance().getValues();

		for (Map.Entry<String, String> iterator : map.entrySet()) {
			ObjectNode entry = radioMapper.createObjectNode();
			entry.put("name", iterator.getKey());
			entry.putPOJO("value", iterator.getValue());
			titlesMap.add(entry);

		}
	} catch (InstantiationException | IllegalAccessException e) {
		ASFUILogger.getLogger().error(e.getMessage());
		throw new RuntimeException(e);
	}

	((ObjectNode) radioFieldFormDefinition).set("titleMap", titlesMap);

}
 
Example 16
Source File: JsonExport.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
protected JsonNode toJson(ControlLink link) {
    ObjectNode l = mapper.createObjectNode();
    if (link instanceof BlockingControlLink) {
        BlockingControlLink controlLink = (BlockingControlLink) link;
        l.putPOJO("block", uriTools.relativeUriForBean(controlLink.getBlock(), 
                link.getParent().getParent()));
        l.putPOJO("untilFinished", uriTools.relativeUriForBean(controlLink.getUntilFinished(), 
                link.getParent().getParent()));
    }
    return l;
}
 
Example 17
Source File: JsonUtil.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
 * 将一个Java对象转换成Json字符串表示
 * @param nodeName 表示该Java对象的节点名称,eg.: user:{"name":"jack","sex":1}; 其中user:即为nodeName
 * @param curObject 支持Map,List
 * @return 如果nodeName为null
 * @throws IOException
 */
public static String convertObject2JsonStr(String nodeName, Object curObject) throws IOException {
    if (curObject != null) {
        if (curObject instanceof JSONObject) {//因为如果是JSONObject对象,会序列化失败 No serializer found for class org.json.JSONObject and no pro
            return curObject.toString();
        }
    }
    if (Util.isEmpty(nodeName)) {
        return mapper.writeValueAsString(curObject);
    }
    ObjectNode rootNode = mapper.createObjectNode();
    rootNode.putPOJO(nodeName, curObject);
    return mapper.writeValueAsString(rootNode);
}
 
Example 18
Source File: Util.java    From tutorials with MIT License 5 votes vote down vote up
public static ObjectNode createResponse(Object response, boolean ok) {
    ObjectNode result = Json.newObject();
    result.put("isSuccessful", ok);
    if (response instanceof String) {
        result.put("body", (String) response);
    } else {
        result.putPOJO("body", response);
    }
    return result;
}
 
Example 19
Source File: Pods.java    From symja_android_library with GNU General Public License v3.0 5 votes vote down vote up
private static ObjectNode errorJSON(String code, String msg) {
	ObjectMapper mapper = new ObjectMapper();
	ObjectNode messageJSON = mapper.createObjectNode();
	ObjectNode queryresult = mapper.createObjectNode();
	messageJSON.putPOJO("queryresult", queryresult);
	queryresult.put("success", "false");
	ObjectNode error = mapper.createObjectNode();
	queryresult.putPOJO("error", error);
	error.put("code", code);
	error.put("msg", msg);
	queryresult.put("numpods", 0);
	queryresult.put("version", "0.1");
	return messageJSON;
}
 
Example 20
Source File: AtlasJson.java    From atlas with Apache License 2.0 3 votes vote down vote up
public static ObjectNode createV1ObjectNode(String key, Object value) {
    ObjectNode ret = mapperV1.createObjectNode();

    ret.putPOJO(key, value);

    return ret;
}