SimpleModule module = new SimpleModule(); module.addSerializer(new ResultSetSerializer()); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(module); [ . . . do the query . . . ] ResultSet resultset = statement.executeQuery(query); // Use the DataBind Api here ObjectNode objectNode = objectMapper.createObjectNode(); // put the resultset in a containing structure objectNode.putPOJO("results", resultset); // generate all objectMapper.writeValue(stringWriter, objectNode);
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 ObjectNode jsonObject(GHResponse ghRsp, boolean enableInstructions, boolean calcPoints, boolean enableElevation, boolean pointsEncoded, float took) { ObjectNode json = JsonNodeFactory.instance.objectNode(); json.putPOJO("hints", ghRsp.getHints().toMap()); jsonPath.put("transfers", ar.getNumChanges()); if (!ar.getDescription().isEmpty()) { jsonPath.putPOJO("description", ar.getDescription()); jsonPath.putPOJO("bbox", ar.calcBBox2D()); jsonPath.putPOJO("points", pointsEncoded ? encodePolyline(ar.getPoints(), enableElevation) : ar.getPoints().toLineString(enableElevation)); if (enableInstructions) { jsonPath.putPOJO("instructions", ar.getInstructions()); jsonPath.putPOJO("legs", ar.getLegs()); jsonPath.putPOJO("details", ar.getPathDetails()); jsonPath.put("ascend", ar.getAscend()); jsonPath.put("descend", ar.getDescend()); jsonPath.putPOJO("snapped_waypoints", pointsEncoded ? encodePolyline(ar.getWaypoints(), enableElevation) : ar.getWaypoints().toLineString(enableElevation)); if (ar.getFare() != null) { jsonPath.put("fare", NumberFormat.getCurrencyInstance(Locale.ROOT).format(ar.getFare()));
@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(); } } }
public void save() { if (fileChannel == null) { return; } ObjectNode rootNode = jsonProcessor.createObjectNode(); rootNode.put("username", username) .put("deviceId", deviceId) .put("isMultiDevice", isMultiDevice) .put("password", password) .put("registrationLockPin", registrationLockPin) .put("signalingKey", signalingKey) .put("preKeyIdOffset", preKeyIdOffset) .put("nextSignedPreKeyId", nextSignedPreKeyId) .put("profileKey", Base64.encodeBytes(profileKey)) .put("registered", registered) .putPOJO("axolotlStore", signalProtocolStore) .putPOJO("groupStore", groupStore) .putPOJO("contactStore", contactStore) .putPOJO("threadStore", threadStore) ; try { fileChannel.position(0); jsonProcessor.writeValue(Channels.newOutputStream(fileChannel), rootNode); fileChannel.truncate(fileChannel.position()); fileChannel.force(false); } catch (Exception e) { System.err.println(String.format("Error saving file: %s", e.getMessage())); } }
@Override public CreateScheduleCommandBuilder dependency_info(DependencyInfo dependency_info) { node.putPOJO("dependency_info", dependency_info); return this; }
@Override public PigCommandBuilder tags(String[] queryTags) { node.putPOJO("tags", queryTags); return this; }
@Override public HadoopCommandBuilder tags(String[] queryTags) { node.putPOJO("tags", queryTags); return this; }
@Override public CreateScheduleCommandBuilder macros(List<Map<String, String>> macros) { node.putPOJO("macros", macros); return this; }
@Override public DbAdvancedImportCommandBuilder tags(String[] queryTags) { node.putPOJO("tags", queryTags); return this; }
@Override public StoreTablePropertiesBuilder columns(Map<String, String> columns) { node.putPOJO("columns", columns); return this; }
@Override public NotebookCommandBuilder tags(String[] tags) { node.putPOJO("tags", tags); return this; }
@Override public DbSimpleExportCommandBuilder tags(String[] queryTags) { node.putPOJO("tags", queryTags); return this; }
public static ObjectNode createV1ObjectNode(String key, Object value) { ObjectNode ret = mapperV1.createObjectNode(); ret.putPOJO(key, value); return ret; }
@Override public FieldMap putAll(Map<String, Field> fieldMap) { ObjectNode objectNode = ((ObjectNode) node); fieldMap.forEach((key, field) -> { objectNode.putPOJO(key, field); }); return this; }
public void updateContainers(List<Container> containers) { // ObjectNode onSpec = retrieveSpec(); // onSpec.putPOJO("containers", containers); JsonNode node = new ObjectMapper().convertValue(spec, JsonNode.class); ObjectNode jnSpec = (ObjectNode)node.path("template").path("spec"); jnSpec.putPOJO("containers", containers); this.spec = new ObjectMapper().convertValue(node, Object.class); }
@Override @SuppressWarnings("deprecation") public ServerConfigBuilder ssl(SSLContext sslContext) { return addToServer(n -> n.putPOJO("jdkSsl", sslContext)); }
ObjectMapper mapper = new ObjectMapper(); JsonNode parsedJson = mapper.readTree(json); //parse the String or do what you already are doing to deserialize the JSON ArrayNode outerArray = mapper.createArrayNode(); //your outer array ObjectNode outerObject = mapper.createObjectNode(); //the object with the "data" array outerObject.putPOJO("data",parsedJson); outerArray.add(outerObject); System.out.println(outerArray.toString()); //just to confirm everything is working
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); node.put("completionTimeUtc", taskExecutionResult.getCompletionTimeUtc().format(DateTimeFormatter.ISO_DATE_TIME)); return node; }