public String toJSON() { ArrayNode array = JACKSON_MAPPER.createArrayNode(); for (RequestAttempt attempt : this) { array.add(attempt.toJsonNode()); } try { return JACKSON_MAPPER.writeValueAsString(array); } catch (JsonProcessingException e) { throw new RuntimeException("Error serializing RequestAttempts!", e); } }
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(); } }
public static void convertMessagesToJson(Collection<Message> messages, ObjectNode propertiesNode) { String propertyName = "messages"; ArrayNode messagesNode = objectMapper.createArrayNode(); for (Message message : messages) { ObjectNode propertyItemNode = objectMapper.createObjectNode(); propertyItemNode.put(PROPERTY_MESSAGE_ID, message.getId()); propertyItemNode.put(PROPERTY_MESSAGE_NAME, message.getName()); propertyItemNode.put(PROPERTY_MESSAGE_ITEM_REF, message.getItemRef()); messagesNode.add(propertyItemNode); } propertiesNode.set(propertyName, messagesNode); }
@Override public JsonNode digest(final JsonNode schema) { // TODO: return an array directly (same for "required" in v4) final ObjectNode ret = FACTORY.objectNode(); final ArrayNode required = FACTORY.arrayNode(); ret.put("required", required); final JsonNode node = schema.get(keyword); final List<String> list = Lists.newArrayList(node.fieldNames()); Collections.sort(list); for (final String field: list) if (node.get(field).path("required").asBoolean(false)) required.add(field); return ret; } }
public static org.apache.avro.Schema getAvroSchema(Schema schema) { ObjectNode avroSchema = JsonUtils.newObjectNode(); avroSchema.put("name", "data_gen_record"); avroSchema.put("type", "record"); ArrayNode fields = JsonUtils.newArrayNode(); for (FieldSpec fieldSpec : schema.getAllFieldSpecs()) { JsonNode jsonObject = fieldSpec.toAvroSchemaJsonObject(); fields.add(jsonObject); } avroSchema.set("fields", fields); return new org.apache.avro.Schema.Parser().parse(avroSchema.toString()); }
private static String writeDependencies(List<DependencyItem> items) { ObjectNode json = JsonNodeFactory.instance.objectNode(); ArrayNode maps = JsonNodeFactory.instance.arrayNode(); items.forEach((dependency) -> maps.add(mapDependency(dependency))); json.set("dependencies", maps); return json.toString(); }
private static void upgradeJdbcPluginPropertiesIfNeeded(ObjectNode propertiesObjectNode) { if (propertiesObjectNode.path("captureBindParameters").asBoolean() && !propertiesObjectNode.has("captureBindParametersIncludes")) { // upgrade from 0.11.1 to 0.11.2 propertiesObjectNode.set("captureBindParametersIncludes", mapper.createArrayNode().add(".*")); propertiesObjectNode.remove("captureBindParameters"); } } }
public static void convertDataPropertiesToJson(List<ValuedDataObject> dataObjects, ObjectNode propertiesNode) { ObjectNode dataPropertiesNode = objectMapper.createObjectNode(); ArrayNode itemsNode = objectMapper.createArrayNode(); for (ValuedDataObject dObj : dataObjects) { ObjectNode propertyItemNode = objectMapper.createObjectNode(); propertyItemNode.put(PROPERTY_DATA_ID, dObj.getId()); propertyItemNode.put(PROPERTY_DATA_NAME, dObj.getName()); String itemSubjectRefQName = dObj.getItemSubjectRef().getStructureRef(); // remove namespace prefix String dataType = itemSubjectRefQName.substring(itemSubjectRefQName.indexOf(':') + 1); propertyItemNode.put(PROPERTY_DATA_TYPE, dataType); Object dObjValue = dObj.getValue(); String value = new String(); if (null == dObjValue) { propertyItemNode.put(PROPERTY_DATA_VALUE, ""); } else { if ("datetime".equals(dataType)) { value = new DateTime(dObjValue).toString("yyyy-MM-dd'T'hh:mm:ss"); } else { value = new String(dObjValue.toString()); } propertyItemNode.put(PROPERTY_DATA_VALUE, value.toString()); } itemsNode.add(propertyItemNode); } dataPropertiesNode.set(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode); propertiesNode.set("dataproperties", dataPropertiesNode); }
@Override public JsonNode digest(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); ret.put("hasAdditional", schema.path("additionalProperties").isObject()); Set<String> set; ArrayNode node; node = FACTORY.arrayNode(); ret.put("properties", node); set = Sets.newHashSet(schema.path("properties").fieldNames()); for (final String field: Ordering.natural().sortedCopy(set)) node.add(field); node = FACTORY.arrayNode(); ret.put("patternProperties", node); set = Sets.newHashSet(schema.path("patternProperties").fieldNames()); for (final String field: Ordering.natural().sortedCopy(set)) node.add(field); return ret; } }
public String getJSONSchema() { ObjectNode jsonSchema = JsonUtils.newObjectNode(); jsonSchema.put("schemaName", _schemaName); if (!_dimensionFieldSpecs.isEmpty()) { ArrayNode jsonArray = JsonUtils.newArrayNode(); for (DimensionFieldSpec dimensionFieldSpec : _dimensionFieldSpecs) { jsonArray.add(dimensionFieldSpec.toJsonObject()); jsonSchema.set("dimensionFieldSpecs", jsonArray); jsonArray.add(metricFieldSpec.toJsonObject()); jsonSchema.set("metricFieldSpecs", jsonArray); jsonSchema.set("timeFieldSpec", _timeFieldSpec.toJsonObject()); jsonArray.add(dateTimeFieldSpec.toJsonObject()); jsonSchema.set("dateTimeFieldSpecs", jsonArray);
public void changeUserTaskCandidateGroup(String id, String candidateGroup, boolean overwriteOtherChangedEntries, ObjectNode infoNode) { ArrayNode valuesNode = null; if (overwriteOtherChangedEntries) { valuesNode = processEngineConfiguration.getObjectMapper().createArrayNode(); } else { if (doesElementPropertyExist(id, USER_TASK_CANDIDATE_GROUPS, infoNode)) { valuesNode = (ArrayNode) infoNode.get(BPMN_NODE).get(id).get(USER_TASK_CANDIDATE_GROUPS); } if (valuesNode == null || valuesNode.isNull()) { valuesNode = processEngineConfiguration.getObjectMapper().createArrayNode(); } } valuesNode.add(candidateGroup); setElementProperty(id, USER_TASK_CANDIDATE_GROUPS, valuesNode, infoNode); }
protected void addFieldExtensions(List<FieldExtension> extensions, ObjectNode propertiesNode) { ObjectNode fieldExtensionsNode = objectMapper.createObjectNode(); ArrayNode itemsNode = objectMapper.createArrayNode(); for (FieldExtension extension : extensions) { ObjectNode propertyItemNode = objectMapper.createObjectNode(); propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_NAME, extension.getFieldName()); if (StringUtils.isNotEmpty(extension.getStringValue())) { propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_STRING_VALUE, extension.getStringValue()); } if (StringUtils.isNotEmpty(extension.getExpression())) { propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_EXPRESSION, extension.getExpression()); } itemsNode.add(propertyItemNode); } fieldExtensionsNode.set("fields", itemsNode); propertiesNode.set(PROPERTY_SERVICETASK_FIELDS, fieldExtensionsNode); }
@Override public JsonNode digest(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); final ObjectNode propertyDeps = FACTORY.objectNode(); ret.put("propertyDeps", propertyDeps); final ArrayNode schemaDeps = FACTORY.arrayNode(); ret.put("schemaDeps", schemaDeps); final List<String> list = Lists.newArrayList(); final Map<String, JsonNode> map = JacksonUtils.asMap(schema.get(keyword)); String key; JsonNode value; for (final Map.Entry<String, JsonNode> entry: map.entrySet()) { key = entry.getKey(); value = entry.getValue(); if (value.isObject()) // schema dep list.add(key); else // property dep propertyDeps.put(key, sortedSet(value)); } for (final String s: Ordering.natural().sortedCopy(list)) schemaDeps.add(s); return ret; }
@Override public String dumpSnapshot(String tableName) throws Exception { ObjectNode ret = JsonUtils.newObjectNode(); ArrayNode routingTableSnapshot = JsonUtils.newArrayNode(); for (String currentTable : _routingTableBuilderMap.keySet()) { if (tableName == null || currentTable.startsWith(tableName)) { ObjectNode tableEntry = JsonUtils.newObjectNode(); tableEntry.put("tableName", currentTable); ArrayNode entries = JsonUtils.newArrayNode(); RoutingTableBuilder routingTableBuilder = _routingTableBuilderMap.get(currentTable); List<Map<String, List<String>>> routingTables = routingTableBuilder.getRoutingTables(); for (Map<String, List<String>> routingTable : routingTables) { entries.add(JsonUtils.objectToJsonNode(routingTable)); } tableEntry.set("routingTableEntries", entries); routingTableSnapshot.add(tableEntry); } } ret.set("routingTableSnapshot", routingTableSnapshot); ret.put("host", NetUtil.getHostnameOrAddress()); return JsonUtils.objectToPrettyString(ret); } }
/** * Map the specified links to a json model. If several links share the same relation, * they are grouped together. * @param links the links to map * @return a model for the specified links */ public static ObjectNode mapLinks(List<Link> links) { ObjectNode result = nodeFactory.objectNode(); Map<String, List<Link>> byRel = new LinkedHashMap<>(); links.forEach((it) -> byRel.computeIfAbsent(it.getRel(), (k) -> new ArrayList<>()) .add(it)); byRel.forEach((rel, l) -> { if (l.size() == 1) { ObjectNode root = JsonNodeFactory.instance.objectNode(); mapLink(l.get(0), root); result.set(rel, root); } else { ArrayNode root = JsonNodeFactory.instance.arrayNode(); l.forEach((link) -> { ObjectNode node = JsonNodeFactory.instance.objectNode(); mapLink(link, node); root.add(node); }); result.set(rel, root); } }); return result; }
public void changeUserTaskCandidateUser(String id, String candidateUser, boolean overwriteOtherChangedEntries, ObjectNode infoNode) { ArrayNode valuesNode = null; if (overwriteOtherChangedEntries) { valuesNode = processEngineConfiguration.getObjectMapper().createArrayNode(); } else { if (doesElementPropertyExist(id, USER_TASK_CANDIDATE_USERS, infoNode)) { valuesNode = (ArrayNode) infoNode.get(BPMN_NODE).get(id).get(USER_TASK_CANDIDATE_USERS); } if (valuesNode == null || valuesNode.isNull()) { valuesNode = processEngineConfiguration.getObjectMapper().createArrayNode(); } } valuesNode.add(candidateUser); setElementProperty(id, USER_TASK_CANDIDATE_USERS, valuesNode, infoNode); }
private void addJsonParameters(String propertyName, String valueName, List<IOParameter> parameterList, ObjectNode propertiesNode) { ObjectNode parametersNode = objectMapper.createObjectNode(); ArrayNode itemsNode = objectMapper.createArrayNode(); for (IOParameter parameter : parameterList) { ObjectNode parameterItemNode = objectMapper.createObjectNode(); if (StringUtils.isNotEmpty(parameter.getSource())) { parameterItemNode.put(PROPERTY_IOPARAMETER_SOURCE, parameter.getSource()); } else { parameterItemNode.putNull(PROPERTY_IOPARAMETER_SOURCE); } if (StringUtils.isNotEmpty(parameter.getTarget())) { parameterItemNode.put(PROPERTY_IOPARAMETER_TARGET, parameter.getTarget()); } else { parameterItemNode.putNull(PROPERTY_IOPARAMETER_TARGET); } if (StringUtils.isNotEmpty(parameter.getSourceExpression())) { parameterItemNode.put(PROPERTY_IOPARAMETER_SOURCE_EXPRESSION, parameter.getSourceExpression()); } else { parameterItemNode.putNull(PROPERTY_IOPARAMETER_SOURCE_EXPRESSION); } itemsNode.add(parameterItemNode); } parametersNode.set(valueName, itemsNode); propertiesNode.set(propertyName, parametersNode); }
@Override public JsonNode digest(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); final ArrayNode allowedTypes = FACTORY.arrayNode(); ret.put(keyword, allowedTypes); final JsonNode node = schema.get(keyword); final EnumSet<NodeType> typeSet = EnumSet.noneOf(NodeType.class); if (node.isTextual()) // Single type typeSet.add(NodeType.fromName(node.textValue())); else // More than one type for (final JsonNode element: node) typeSet.add(NodeType.fromName(element.textValue())); if (typeSet.contains(NodeType.NUMBER)) typeSet.add(NodeType.INTEGER); /* * Note that as this is an enumset, order is guaranteed */ for (final NodeType type: typeSet) allowedTypes.add(type.toString()); return ret; } }
segmentMetadata.put("segmentName", _segmentName); segmentMetadata.put("schemaName", _schema != null ? _schema.getSchemaName() : null); segmentMetadata.put("crc", _crc); segmentMetadata.put("creationTimeMillis", _creationTime); TimeZone timeZone = TimeZone.getTimeZone("UTC"); segmentMetadata.put("timeGranularitySec", _timeGranularity != null ? _timeGranularity.getStandardSeconds() : null); if (_timeInterval == null) { segmentMetadata.set("startTimeMillis", null); segmentMetadata.set("startTimeReadable", null); segmentMetadata.set("endTimeMillis", null); segmentMetadata.set("endTimeReadable", null); } else { continue; columnsMetadata.add(JsonUtils.objectToJsonNode(_columnMetadataMap.get(column))); segmentMetadata.set("columns", columnsMetadata);