Java Code Examples for com.fasterxml.jackson.databind.node.ObjectNode#putObject()
The following examples show how to use
com.fasterxml.jackson.databind.node.ObjectNode#putObject() .
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: LinkWriter.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Writes a {@link Link} object to the JSON tree. * * @param parent * @param model * @param name */ private static void writeLink(ObjectNode parent, Link model, String name) { if (model == null) { return; } ObjectNode node = parent.putObject(name); if (StringUtil.isNotEmpty(model.getRef())) { JsonUtil.stringProperty(node, Referenceable.PROP_$REF, model.getRef()); } else { JsonUtil.stringProperty(node, OpenApiConstants.PROP_OPERATION_REF, model.getOperationRef()); JsonUtil.stringProperty(node, OpenApiConstants.PROP_OPERATION_ID, model.getOperationId()); writeLinkParameters(node, model.getParameters()); ObjectWriter.writeObject(node, LinkConstant.PROP_REQUEST_BODY, model.getRequestBody()); JsonUtil.stringProperty(node, LinkConstant.PROP_DESCRIPTION, model.getDescription()); ServerWriter.writeServer(node, model.getServer()); ExtensionWriter.writeExtensions(node, model); } }
Example 2
Source File: OperationWriter.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Writes a {@link Operation} to the JSON tree. * * @param parent the parent json node * @param model the Operation model * @param method the name of the node (operation method) */ public static void writeOperation(ObjectNode parent, Operation model, String method) { if (model == null) { return; } ObjectNode node = parent.putObject(method); ObjectWriter.writeStringArray(node, model.getTags(), OperationConstant.PROP_TAGS); JsonUtil.stringProperty(node, OperationConstant.PROP_SUMMARY, model.getSummary()); JsonUtil.stringProperty(node, OperationConstant.PROP_DESCRIPTION, model.getDescription()); ExternalDocsWriter.writeExternalDocumentation(node, model.getExternalDocs()); JsonUtil.stringProperty(node, OperationConstant.PROP_OPERATION_ID, model.getOperationId()); ParameterWriter.writeParameterList(node, model.getParameters()); RequestBodyWriter.writeRequestBody(node, model.getRequestBody()); ResponseWriter.writeAPIResponses(node, model.getResponses()); CallbackWriter.writeCallbacks(node, model.getCallbacks()); JsonUtil.booleanProperty(node, OperationConstant.PROP_DEPRECATED, model.getDeprecated()); SecurityRequirementWriter.writeSecurityRequirements(node, model.getSecurity()); ServerWriter.writeServers(node, model.getServers()); ExtensionWriter.writeExtensions(node, model); }
Example 3
Source File: NavigateResponseConverter.java From graphhopper-navigation with Apache License 2.0 | 6 votes |
private static void putManeuver(Instruction instruction, ObjectNode instructionJson, Locale locale, TranslationMap translationMap, boolean isFirstInstructionOfLeg) { ObjectNode maneuver = instructionJson.putObject("maneuver"); maneuver.put("bearing_after", 0); maneuver.put("bearing_before", 0); PointList points = instruction.getPoints(); putLocation(points.getLat(0), points.getLon(0), maneuver); String modifier = getModifier(instruction); if (modifier != null) maneuver.put("modifier", modifier); maneuver.put("type", getTurnType(instruction, isFirstInstructionOfLeg)); // exit number if (instruction instanceof RoundaboutInstruction) maneuver.put("exit", ((RoundaboutInstruction) instruction).getExitNumber()); maneuver.put("instruction", instruction.getTurnDescription(translationMap.getWithFallBack(locale))); }
Example 4
Source File: CallbackWriter.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Writes a {@link Callback} object to the JSON tree. * * @param parent the parent node * @param model the callback model * @param name the name of the node */ private static void writeCallback(ObjectNode parent, Callback model, String name) { if (model == null) { return; } ObjectNode node = parent.putObject(name); if (StringUtil.isNotEmpty(model.getRef())) { JsonUtil.stringProperty(node, Referenceable.PROP_$REF, model.getRef()); } else { if (model.getPathItems() != null) { Set<Map.Entry<String, PathItem>> entrySet = model.getPathItems().entrySet(); for (Map.Entry<String, PathItem> entry : entrySet) { PathsWriter.writePathItem(node, entry.getValue(), entry.getKey()); } } ExtensionWriter.writeExtensions(node, model); } }
Example 5
Source File: SecuritySchemeWriter.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Writes a {@link SecurityScheme} object to the JSON tree. * * @param parent * @param model * @param name */ private static void writeSecurityScheme(ObjectNode parent, SecurityScheme model, String name) { if (model == null) { return; } ObjectNode node = parent.putObject(name); if (StringUtil.isNotEmpty(model.getRef())) { JsonUtil.stringProperty(node, Referenceable.PROP_$REF, model.getRef()); } else { JsonUtil.enumProperty(node, SecuritySchemeConstant.PROP_TYPE, model.getType()); JsonUtil.stringProperty(node, SecuritySchemeConstant.PROP_DESCRIPTION, model.getDescription()); JsonUtil.stringProperty(node, SecuritySchemeConstant.PROP_NAME, model.getName()); JsonUtil.enumProperty(node, SecuritySchemeConstant.PROP_IN, model.getIn()); JsonUtil.stringProperty(node, SecuritySchemeConstant.PROP_SCHEME, model.getScheme()); JsonUtil.stringProperty(node, SecuritySchemeConstant.PROP_BEARER_FORMAT, model.getBearerFormat()); OAuthWriter.writeOAuthFlows(node, model.getFlows()); JsonUtil.stringProperty(node, SecuritySchemeConstant.PROP_OPEN_ID_CONNECT_URL, model.getOpenIdConnectUrl()); ExtensionWriter.writeExtensions(node, model); } }
Example 6
Source File: NodeMergeTest.java From jackson-modules-base with Apache License 2.0 | 6 votes |
public void testObjectDeepUpdate() throws Exception { ObjectNode base = MAPPER.createObjectNode(); ObjectNode props = base.putObject("props"); props.put("base", 123); props.put("value", 456); ArrayNode a = props.putArray("array"); a.add(true); base.putNull("misc"); assertSame(base, MAPPER.readerForUpdating(base) .readValue(aposToQuotes( "{'props':{'value':true, 'extra':25.5, 'array' : [ 3 ]}}"))); assertEquals(2, base.size()); ObjectNode resultProps = (ObjectNode) base.get("props"); assertEquals(4, resultProps.size()); assertEquals(123, resultProps.path("base").asInt()); assertTrue(resultProps.path("value").asBoolean()); assertEquals(25.5, resultProps.path("extra").asDouble()); JsonNode n = resultProps.get("array"); assertEquals(ArrayNode.class, n.getClass()); assertEquals(2, n.size()); assertEquals(3, n.get(1).asInt()); }
Example 7
Source File: HerokuDeployApi.java From heroku-maven-plugin with MIT License | 5 votes |
public BuildInfo createBuild(String appName, URI sourceBlob, String sourceBlobVersion, List<String> buildpacks) throws IOException, HerokuDeployApiException { // Create API payload ObjectMapper mapper = new ObjectMapper(); ObjectNode root = mapper.createObjectNode(); ObjectNode sourceBlobObject = root.putObject("source_blob"); sourceBlobObject.put("url", sourceBlob.toString()); sourceBlobObject.put("version", sourceBlobVersion); ArrayNode buildpacksArray = root.putArray("buildpacks"); buildpacks.forEach(buildpackString -> { ObjectNode buildpackObjectNode = buildpacksArray.addObject(); if (buildpackString.startsWith("http")) { buildpackObjectNode.put("url", buildpackString); } else { buildpackObjectNode.put("name", buildpackString); } }); StringEntity apiPayloadEntity = new StringEntity(root.toString()); apiPayloadEntity.setContentType("application/json"); apiPayloadEntity.setContentEncoding("UTF-8"); // Send request CloseableHttpClient client = HttpClients.createSystem(); HttpPost request = new HttpPost("https://api.heroku.com/apps/" + appName + "/builds"); httpHeaders.forEach(request::setHeader); request.setEntity(apiPayloadEntity); CloseableHttpResponse response = client.execute(request); return handleBuildInfoResponse(appName, mapper, response); }
Example 8
Source File: OpenApi3Utils.java From vertx-web with Apache License 2.0 | 5 votes |
private static void replaceRef(ObjectNode n, ObjectNode root, OpenAPI oas) { /** * If a ref is found, the structure of the schema is circular. The oas parser don't solve circular refs. * So I bundle the schema: * 1. I update the ref field with a #/definitions/schema_name uri * 2. If #/definitions/schema_name is empty, I solve it */ String oldRef = n.get("$ref").asText(); Matcher m = COMPONENTS_REFS_MATCHER.matcher(oldRef); if (m.lookingAt()) { String schemaName = m.group(1); String newRef = m.replaceAll(COMPONENTS_REFS_SUBSTITUTION); n.remove("$ref"); n.put("$ref", newRef); if (!root.has("definitions") || !root.get("definitions").has(schemaName)) { Schema s = oas.getComponents().getSchemas().get(schemaName); ObjectNode schema = ObjectMapperFactory.createJson().convertValue(s, ObjectNode.class); // We need to search inside for other refs if (!root.has("definitions")) { ObjectNode definitions = root.putObject("definitions"); definitions.set(schemaName, schema); } else { ((ObjectNode)root.get("definitions")).set(schemaName, schema); } walkAndSolve(schema, root, oas); } } else throw new RuntimeException("Wrong ref! " + oldRef); }
Example 9
Source File: DynamicBpmnServiceImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
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); }
Example 10
Source File: ExpressionJsonVisitor.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void putParameters(ObjectNode node, final String name, final List<UriParameter> parameters) { if (!parameters.isEmpty()) { ObjectNode parametersNode = node.putObject(name); for (final UriParameter parameter : parameters) { parametersNode.put(parameter.getName(), parameter.getText() == null ? parameter.getAlias() : parameter.getText()); } } }
Example 11
Source File: ResponseWriter.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Writes a {@link APIResponses} map to the JSON tree. * * @param parent the parent json node * @param model APIResponse model */ public static void writeAPIResponses(ObjectNode parent, APIResponses model) { if (model == null) { return; } ObjectNode node = parent.putObject(ComponentsConstant.PROP_RESPONSES); writeAPIResponse(node, model.getDefaultValue(), ResponseConstant.PROP_DEFAULT); if (model.getAPIResponses() != null) { Set<Map.Entry<String, APIResponse>> entrySet = model.getAPIResponses().entrySet(); for (Map.Entry<String, APIResponse> entry : entrySet) { writeAPIResponse(node, entry.getValue(), entry.getKey()); } } }
Example 12
Source File: LicenseWriter.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Writes the {@link License} model to the JSON tree. * * @param parent the parent json node * @param model the License model */ public static void writeLicense(ObjectNode parent, License model) { if (model == null) { return; } ObjectNode node = parent.putObject(InfoConstant.PROP_LICENSE); JsonUtil.stringProperty(node, LicenseConstant.PROP_NAME, model.getName()); JsonUtil.stringProperty(node, LicenseConstant.PROP_URL, model.getUrl()); ExtensionWriter.writeExtensions(node, model); }
Example 13
Source File: UnifiedJsonDataShapeSupport.java From syndesis with Apache License 2.0 | 5 votes |
protected static DataShape unifiedJsonSchema(final String name, final String description, final ObjectNode bodySchema, final ObjectNode parametersSchema) { if (bodySchema == null && parametersSchema == null) { return DATA_SHAPE_NONE; } final ObjectNode unifiedSchema = JsonSchemaHelper.newJsonObjectSchema(); unifiedSchema.put("$id", "io:syndesis:wrapped"); final ObjectNode properties = unifiedSchema.putObject("properties"); if (parametersSchema != null) { properties.remove(PROPERTIES_TO_REMOVE_ON_MERGE); properties.set("parameters", parametersSchema.get("properties").get("parameters")); } if (bodySchema != null) { bodySchema.remove(PROPERTIES_TO_REMOVE_ON_MERGE); properties.set("body", bodySchema); } return new DataShape.Builder()// .name(name)// .description(description)// .kind(DataShapeKinds.JSON_SCHEMA)// .specification(JsonSchemaHelper.serializeJson(unifiedSchema))// .putMetadata(DataShapeMetaData.UNIFIED, "true") .build(); }
Example 14
Source File: ResolverCacheTest.java From swagger-parser with Apache License 2.0 | 5 votes |
private Pair<JsonNode, JsonNode> constructJsonTree(String... properties) { JsonNodeFactory factory = new JsonNodeFactory(true); final ObjectNode parent = factory.objectNode(); ObjectNode current = parent; for (String property : properties) { current = current.putObject(property); } current.put("key", "value"); return Pair.of((JsonNode) parent, (JsonNode) current); }
Example 15
Source File: NavigateResponseConverter.java From graphhopper-navigation with Apache License 2.0 | 5 votes |
/** * Banner instructions are the turn instructions that are shown to the user in the top bar. * <p> * Between two instructions we can show multiple banner instructions, you can control when they pop up using distanceAlongGeometry. */ private static void putBannerInstructions(InstructionList instructions, double distance, int index, Locale locale, TranslationMap translationMap, ArrayNode bannerInstructions) { /* A BannerInstruction looks like this distanceAlongGeometry: 107, primary: { text: "Lichtensteinstraße", components: [ { text: "Lichtensteinstraße", type: "text", } ], type: "turn", modifier: "right", }, secondary: null, */ ObjectNode bannerInstruction = bannerInstructions.addObject(); //Show from the beginning bannerInstruction.put("distanceAlongGeometry", distance); ObjectNode primary = bannerInstruction.putObject("primary"); putSingleBannerInstruction(instructions.get(index + 1), locale, translationMap, primary); bannerInstruction.putNull("secondary"); if (instructions.size() > index + 2 && instructions.get(index + 2).getSign() != Instruction.REACHED_VIA) { // Sub shows the instruction after the current one ObjectNode sub = bannerInstruction.putObject("sub"); putSingleBannerInstruction(instructions.get(index + 2), locale, translationMap, sub); } }
Example 16
Source File: EncodingWriter.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Writes a map of {@link Encoding} objects to the JSON tree. * * @param parent the parent json node * @param models map of Encoding models */ public static void writeEncodings(ObjectNode parent, Map<String, Encoding> models) { if (models == null) { return; } ObjectNode node = parent.putObject(EncodingConstant.PROP_ENCODING); for (Map.Entry<String, Encoding> entry : models.entrySet()) { writeEncoding(node, entry.getValue(), entry.getKey()); } }
Example 17
Source File: MapMatchingResource.java From map-matching with Apache License 2.0 | 5 votes |
static JsonNode convertToTree(MatchResult result, boolean elevation, boolean pointsEncoded) { ObjectNode root = JsonNodeFactory.instance.objectNode(); ObjectNode diary = root.putObject("diary"); ArrayNode entries = diary.putArray("entries"); ObjectNode route = entries.addObject(); ArrayNode links = route.putArray("links"); for (int emIndex = 0; emIndex < result.getEdgeMatches().size(); emIndex++) { ObjectNode link = links.addObject(); EdgeMatch edgeMatch = result.getEdgeMatches().get(emIndex); PointList pointList = edgeMatch.getEdgeState().fetchWayGeometry(emIndex == 0 ? FetchMode.ALL : FetchMode.PILLAR_AND_ADJ); final ObjectNode geometry = link.putObject("geometry"); if (pointList.size() < 2) { geometry.putPOJO("coordinates", pointsEncoded ? WebHelper.encodePolyline(pointList, elevation) : pointList.toLineString(elevation)); geometry.put("type", "Point"); } else { geometry.putPOJO("coordinates", pointsEncoded ? WebHelper.encodePolyline(pointList, elevation) : pointList.toLineString(elevation)); geometry.put("type", "LineString"); } link.put("id", edgeMatch.getEdgeState().getEdge()); ArrayNode wpts = link.putArray("wpts"); for (State extension : edgeMatch.getStates()) { ObjectNode wpt = wpts.addObject(); wpt.put("x", extension.getQueryResult().getSnappedPoint().lon); wpt.put("y", extension.getQueryResult().getSnappedPoint().lat); } } return root; }
Example 18
Source File: MoneyFormatterTest.java From template-compiler with Apache License 2.0 | 5 votes |
private static ObjectNode moneyBase(String currencyCode, boolean useCLDR) { ObjectNode obj = JsonUtils.createObjectNode(); obj.put("currency", currencyCode); ObjectNode website = obj.putObject("website"); website.put("useCLDRMoneyFormat", useCLDR); return obj; }
Example 19
Source File: UnifiedJsonDataShapeGenerator.java From syndesis with Apache License 2.0 | 4 votes |
private static ObjectNode createSchemaFor(final List<Oas30Parameter> parameterList) { if (parameterList.isEmpty()) { return null; } final ObjectNode schema = JsonSchemaHelper.newJsonObjectSchema(); final ObjectNode properties = schema.putObject("properties"); final ObjectNode parameters = properties.putObject("parameters"); parameters.put("type", "object"); final ObjectNode parametersProperties = parameters.putObject("properties"); for (final Oas30Parameter parameter : parameterList) { final Optional<Oas30Schema> maybeParameterSchema = Oas30ModelHelper.getSchema(parameter); if (!maybeParameterSchema.isPresent()) { continue; } final Oas30Schema parameterSchema = maybeParameterSchema.get(); final String type = parameterSchema.type; final String name = trimToNull(parameter.getName()); final String description = trimToNull(parameter.description); if ("file".equals(type)) { // 'file' type is not allowed in JSON schema continue; } final ObjectNode parameterParameter = parametersProperties.putObject(name); if (type != null) { parameterParameter.put("type", type); } if (name != null) { parameterParameter.put("title", name); } if (description != null) { parameterParameter.put("description", description); } final Object defaultValue = parameterSchema.default_; if (defaultValue != null) { parameterParameter.put("default", String.valueOf(defaultValue)); } addEnumsTo(parameterParameter, parameterSchema); } return schema; }
Example 20
Source File: StoreSubmittedFormCmd.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public SubmittedForm execute(CommandContext commandContext) { if (formDefinition == null || formDefinition.getId() == null) { throw new ActivitiFormException("Invalid form definition provided"); } ObjectMapper objectMapper = commandContext.getFormEngineConfiguration().getObjectMapper(); ObjectNode submittedFormValuesJson = objectMapper.createObjectNode(); ObjectNode valuesNode = submittedFormValuesJson.putObject("values"); // Loop over all form fields and see if a value was provided Map<String, FormField> fieldMap = formDefinition.allFieldsAsMap(); for (String fieldId : fieldMap.keySet()) { FormField formField = fieldMap.get(fieldId); if (FormFieldTypes.EXPRESSION.equals(formField.getType()) || FormFieldTypes.CONTAINER.equals(formField.getType())) { continue; } if (variables.containsKey(fieldId)) { Object variableValue = variables.get(fieldId); if (variableValue == null) { valuesNode.putNull(fieldId); } else if (variableValue instanceof Long) { valuesNode.put(fieldId, (Long) variables.get(fieldId)); } else if (variableValue instanceof Double) { valuesNode.put(fieldId, (Double) variables.get(fieldId)); } else if (variableValue instanceof LocalDate) { valuesNode.put(fieldId, ((LocalDate) variableValue).toString()); } else { valuesNode.put(fieldId, variableValue.toString()); } } } // Handle outcome String outcomeVariable = null; if (formDefinition.getOutcomeVariableName() != null) { outcomeVariable = formDefinition.getOutcomeVariableName(); } else { outcomeVariable = "form_" + formDefinition.getKey() + "_outcome"; } if (variables.containsKey(outcomeVariable) && variables.get(outcomeVariable) != null) { submittedFormValuesJson.put("activiti_form_outcome", variables.get(outcomeVariable).toString()); } SubmittedFormEntityManager submittedFormEntityManager = commandContext.getSubmittedFormEntityManager(); SubmittedFormEntity submittedFormEntity = submittedFormEntityManager.create(); submittedFormEntity.setFormId(formDefinition.getId()); submittedFormEntity.setTaskId(taskId); submittedFormEntity.setProcessInstanceId(processInstanceId); submittedFormEntity.setSubmittedDate(new Date()); try { submittedFormEntity.setFormValueBytes(objectMapper.writeValueAsBytes(submittedFormValuesJson)); } catch (Exception e) { throw new ActivitiFormException("Error setting form values JSON", e); } submittedFormEntityManager.insert(submittedFormEntity); return submittedFormEntity; }