/** * Example to writeJson using TreeModel */ private static void writeJson() throws IOException { OutputStream outputStream = new ByteArrayOutputStream(); ObjectMapper mapper = new ObjectMapper(); ObjectNode rootNode = mapper.createObjectNode(); rootNode.put("message", "Hi"); ObjectNode childNode = rootNode.putObject("place"); childNode.put("name", "World!"); mapper.writeValue(outputStream, childNode); System.out.println(outputStream.toString()); // print "{"message":"Hi","place":{"name":"World!"}}" } }
protected ObjectNode createOrGetBpmnNode(ObjectNode infoNode) { if (!infoNode.has(BPMN_NODE)) { infoNode.putObject(BPMN_NODE); } return (ObjectNode) infoNode.get(BPMN_NODE); }
protected ObjectNode createOrGetLocalizationNode(ObjectNode infoNode) { if (!infoNode.has(LOCALIZATION_NODE)) { infoNode.putObject(LOCALIZATION_NODE); } return (ObjectNode) infoNode.get(LOCALIZATION_NODE); }
protected void setLocalizationProperty(String language, String id, String propertyName, String propertyValue, ObjectNode infoNode) { ObjectNode localizationNode = createOrGetLocalizationNode(infoNode); if (!localizationNode.has(language)) { localizationNode.putObject(language); } ObjectNode languageNode = (ObjectNode) localizationNode.get(language); if (!languageNode.has(id)) { languageNode.putObject(id); } ((ObjectNode) languageNode.get(id)).put(propertyName, propertyValue); }
protected void setElementProperty(String id, String propertyName, JsonNode propertyValue, ObjectNode infoNode) { ObjectNode bpmnNode = createOrGetBpmnNode(infoNode); if (!bpmnNode.has(id)) { bpmnNode.putObject(id); } ((ObjectNode) bpmnNode.get(id)).set(propertyName, propertyValue); }
protected void setElementProperty(String id, String propertyName, String propertyValue, ObjectNode infoNode) { ObjectNode bpmnNode = createOrGetBpmnNode(infoNode); if (!bpmnNode.has(id)) { bpmnNode.putObject(id); } ((ObjectNode) bpmnNode.get(id)).put(propertyName, propertyValue); }
private Response jsonSuccessResponse(Object result, float took) { ObjectNode json = JsonNodeFactory.instance.objectNode(); json.putPOJO("polygons", result); // If you replace GraphHopper with your own brand name, this is fine. // Still it would be highly appreciated if you mention us in your about page! final ObjectNode info = json.putObject("info"); info.putArray("copyrights") .add("GraphHopper") .add("OpenStreetMap contributors"); info.put("took", Math.round(took * 1000)); return Response.ok(json).build(); } }
final ObjectNode info = json.putObject("info"); info.putArray("copyrights") .add("GraphHopper")
@Override public ObjectNode toJSON() { JsonNodeFactory nf = JsonNodeFactory.instance; ObjectNode json = nf.objectNode(); json.put("format", "json"); json.put("entity_type", entityType.getName()); if (!attributes.isEmpty()) { ObjectNode attrNode = json.putObject("attributes"); for (Map.Entry<String,TypedName<?>> attr: attributes.entrySet()) { ObjectNode an = attrNode.putObject(attr.getKey()); an.put("name", attr.getValue().getName()); an.put("type", TypeUtils.makeTypeName(attr.getValue().getType())); } } return json; }
protected ObjectNode createOrGetLocalizationNode(ObjectNode infoNode) { if (!infoNode.has(LOCALIZATION_NODE)) { infoNode.putObject(LOCALIZATION_NODE); } return (ObjectNode) infoNode.get(LOCALIZATION_NODE); }
private JsonNode node(JsonNode node) { if (node instanceof ObjectNode) { return ((ObjectNode) node).putObject(currentFieldName); } else if (node instanceof ArrayNode) { return ((ArrayNode) node).addObject(); } else { return JsonNodeFactory.instance.objectNode(); } } }
protected ObjectNode createOrGetLocalizationNode(ObjectNode infoNode) { if (infoNode.has(LOCALIZATION_NODE) == false) { infoNode.putObject(LOCALIZATION_NODE); } return (ObjectNode) infoNode.get(LOCALIZATION_NODE); }
protected void setLocalizationProperty(String language, String id, String propertyName, String propertyValue, ObjectNode infoNode) { ObjectNode localizationNode = createOrGetLocalizationNode(infoNode); if (localizationNode.has(language) == false) { localizationNode.putObject(language); } ObjectNode languageNode = (ObjectNode) localizationNode.get(language); if (languageNode.has(id) == false) { languageNode.putObject(id); } ((ObjectNode) languageNode.get(id)).put(propertyName, propertyValue); }
protected void setLocalizationProperty(String language, String id, String propertyName, String propertyValue, ObjectNode infoNode) { ObjectNode localizationNode = createOrGetLocalizationNode(infoNode); if (!localizationNode.has(language)) { localizationNode.putObject(language); } ObjectNode languageNode = (ObjectNode) localizationNode.get(language); if (!languageNode.has(id)) { languageNode.putObject(id); } ((ObjectNode) languageNode.get(id)).put(propertyName, propertyValue); }
protected void setElementProperty(String id, String propertyName, JsonNode propertyValue, ObjectNode infoNode) { ObjectNode bpmnNode = createOrGetBpmnNode(infoNode); if (bpmnNode.has(id) == false) { bpmnNode.putObject(id); } ((ObjectNode) bpmnNode.get(id)).set(propertyName, propertyValue); }
protected void setElementProperty(String id, String propertyName, String propertyValue, ObjectNode infoNode) { ObjectNode bpmnNode = createOrGetBpmnNode(infoNode); if (!bpmnNode.has(id)) { bpmnNode.putObject(id); } ((ObjectNode) bpmnNode.get(id)).put(propertyName, propertyValue); }
protected void setElementProperty(String id, String propertyName, String propertyValue, ObjectNode infoNode) { ObjectNode bpmnNode = createOrGetBpmnNode(infoNode); if (bpmnNode.has(id) == false) { bpmnNode.putObject(id); } ((ObjectNode) bpmnNode.get(id)).put(propertyName, propertyValue); }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { OduSignalId oduSignalId = ((OduSignalIdCriterion) criterion).oduSignalId(); ObjectNode child = root.putObject(CriterionCodec.ODU_SIGNAL_ID); child.put(CriterionCodec.TRIBUTARY_PORT_NUMBER, oduSignalId.tributaryPortNumber()); child.put(CriterionCodec.TRIBUTARY_SLOT_LEN, oduSignalId.tributarySlotLength()); child.put(CriterionCodec.TRIBUTARY_SLOT_BITMAP, HexString.toHexString(oduSignalId.tributarySlotBitmap())); return root; } }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { OchSignal ochSignal = ((OchSignalCriterion) criterion).lambda(); ObjectNode child = root.putObject(CriterionCodec.OCH_SIGNAL_ID); child.put(CriterionCodec.GRID_TYPE, ochSignal.gridType().name()); child.put(CriterionCodec.CHANNEL_SPACING, ochSignal.channelSpacing().name()); child.put(CriterionCodec.SPACING_MULIPLIER, ochSignal.spacingMultiplier()); child.put(CriterionCodec.SLOT_GRANULARITY, ochSignal.slotGranularity()); return root; } }