List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put
public ObjectNode put(String paramString1, String paramString2)
From source file:transformation.CsvExportTest.java
@Test public void testMissingField() { ObjectNode org = Json.newObject(); org.put("field1", "org1-value1"); org.put("field2", "org1-value2"); org.put("field3", "org1-value3"); CsvExport export = new CsvExport(Json.stringify(Json.toJson(Arrays.asList(org)))); String expected = String.format("%s,%s\n%s,%s\n", // "field1", "no-such-field", // "\"org1-value1\"", ""); assertThat(export.of("field1,no-such-field")).isEqualTo(expected); }
From source file:com.jivesoftware.jive.deployer.jaxrs.util.ResponseHelperTest.java
@Test public void testErrorResponse() throws Exception { ObjectNode jsonNode = objectMapper.createObjectNode(); jsonNode.put("Foobar", true); String message = "This is a BAD request!"; Exception e = new Exception(); OutputStream outputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outputStream); e.printStackTrace(printStream);/*from w w w.j a v a 2s.c o m*/ Response response = ResponseHelper.INSTANCE.errorResponse(Response.Status.BAD_REQUEST, message, e, jsonNode); assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode()); String bodyString = objectMapper.writeValueAsString(response.getEntity()); System.out.println(bodyString); ObjectNode body = (ObjectNode) objectMapper.readTree(bodyString); assertEquals(body.get("message").textValue(), message); assertEquals(body.get("trace").textValue(), outputStream.toString()); assertEquals(body.get("relatedData"), jsonNode); }
From source file:ws.doerr.cssinliner.server.ConfigApi.java
@Path("/email/providers") @GET//from w w w . ja v a 2 s . com @Produces(MediaType.APPLICATION_JSON) public Response getProviders() { ObjectNode rc = Server.getMapper().createObjectNode(); rc.put("current", EmailService.getProvider()); ArrayNode available = rc.putArray("available"); EmailService.getAvailable().forEach((clazz, name) -> { available.addObject().put("key", clazz).put("value", name); }); return Response.ok(rc).build(); }
From source file:com.dhenton9000.json.processing.FasterXMLJSONTests.java
@Test public void testModifyTree() throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode sampleTree = mapper.readTree(TEST_STRING); JsonNode jsonNodeValue = sampleTree.get("alpha"); ObjectNode sampleObj = (ObjectNode) sampleTree; sampleObj.put("alpha", 99); assertEquals(sampleTree.get("alpha").intValue(), 99); // ob.put("alpha", 555); // or int, long, boolean etc }
From source file:com.ibm.watson.catalyst.corpus.Corpus.java
/** * Converts the corpus to JSON form//from www .ja v a2 s . c o m * @return a JSON representation of the Corpus */ public ObjectNode toObjectNode() { ObjectNode result = MAPPER.createObjectNode(); result.put("corpus-name", _name); result.set("documents", JsonUtil.toArrayNodeJsonable(_documents)); return result; }
From source file:net.logstash.logback.LogstashAccessFormatter.java
private void createFields(IAccessEvent event, Context context, ObjectNode eventNode) { eventNode.put("@fields.method", event.getMethod()); eventNode.put("@fields.protocol", event.getProtocol()); eventNode.put("@fields.status_code", event.getStatusCode()); eventNode.put("@fields.requested_url", event.getRequestURL()); eventNode.put("@fields.requested_uri", event.getRequestURI()); eventNode.put("@fields.remote_host", event.getRemoteHost()); eventNode.put("@fields.HOSTNAME", event.getRemoteHost()); eventNode.put("@fields.remote_user", event.getRemoteUser()); eventNode.put("@fields.content_length", event.getContentLength()); if (context != null) { addPropertiesAsFields(eventNode, context.getCopyOfPropertyMap()); }/*from w ww . j av a2 s. com*/ }
From source file:com.rusticisoftware.tincan.StatementRef.java
@Override public ObjectNode toJSONNode(TCAPIVersion version) { ObjectNode node = Mapper.getInstance().createObjectNode(); node.put("objectType", this.objectType); node.put("id", this.getId().toString()); return node;// w ww . j a v a 2 s . c om }
From source file:org.envirocar.server.rest.encoding.json.StatisticJSONEncoder.java
@Override public ObjectNode encodeJSON(Statistic t, AccessRights rights, MediaType mt) { ObjectNode statistic = getJsonFactory().objectNode(); statistic.put(JSONConstants.MAX_KEY, t.getMax()); statistic.put(JSONConstants.AVG_KEY, t.getMean()); statistic.put(JSONConstants.MIN_KEY, t.getMin()); statistic.put(JSONConstants.MEASUREMENTS_KEY, t.getMeasurements()); statistic.put(JSONConstants.TRACKS_KEY, t.getTracks()); statistic.put(JSONConstants.USERS_KEY, t.getUsers()); statistic.put(JSONConstants.SENSORS_KEY, t.getSensors()); statistic.put(JSONConstants.PHENOMENON_KEY, phenomenonEncoder.encodeJSON(t.getPhenomenon(), rights, mt)); return statistic; }
From source file:securesocial.core.java.DefaultSecuredActionResponses.java
public F.Promise<Result> notAuthorizedResult(Http.Context ctx) { Http.Request req = ctx.request(); Result result;/* w ww . j av a2 s. c o m*/ if (req.accepts("text/html")) { result = forbidden(notAuthorizedPage(ctx)); } else if (req.accepts("application/json")) { ObjectNode node = Json.newObject(); node.put("error", "Not authorized"); result = forbidden(node); } else { result = forbidden("Not authorized"); } return F.Promise.pure(result); }
From source file:azkaban.crypto.CryptoV1_1.java
@Override public String encrypt(String plaintext, String passphrase, Version cryptoVersion) { Preconditions.checkArgument(Version.V1_1.equals(cryptoVersion)); String cipheredText = newEncryptor(passphrase).encrypt(plaintext); ObjectNode node = MAPPER.createObjectNode(); node.put(CIPHERED_TEXT_KEY, cipheredText); node.put(ICrypto.VERSION_IDENTIFIER, Version.V1_1.versionStr()); return Crypto.encode(node.toString()); }