List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:org.zalando.stups.swagger.codegen.YamlToJsonTest.java
@Test public void transform() throws JsonProcessingException, IOException { String data = getResourceContent("/kio-api.yaml"); ObjectMapper yamlMapper = Yaml.mapper(); JsonNode rootNode = yamlMapper.readTree(data); // must have swagger node set JsonNode swaggerNode = rootNode.get("swagger"); String rootNodeString = rootNode.toString(); System.out.println(rootNodeString); }
From source file:com.github.fge.jsonpatch.serialization.JsonPatchOperationSerializationTest.java
@Test(dataProvider = "getInputs") public final void patchOperationSerializationWorks(final JsonNode input) throws IOException { /*/*from w ww. ja v a 2s . c om*/ * Deserialize a string input */ final String in = input.toString(); final JsonPatchOperation op = mapper.readValue(in, JsonPatchOperation.class); /* * Check that the class of the operation is what is expected */ assertSame(op.getClass(), c); /* * Now, write the operation as a String... */ final String out = mapper.writeValueAsString(op); /* * And read it as a JsonNode again, then test for equality. * * The reason we do that is that JSON does not guarantee the order of * object members; but JsonNode's .equals() method will correctly handle * this event, and we trust its .toString(). */ final JsonNode output = JacksonUtils.getReader().readTree(out); assertTrue(EQUIVALENCE.equivalent(input, output)); }
From source file:com.infinities.keystone4j.admin.v3.ednpoint.EndpointResourceTest.java
@Test public void testUpdateEndpoint() throws ClientProtocolException, IOException { endpoint.setName("newName"); EndpointWrapper wrapper = new EndpointWrapper(endpoint); PatchClient client = new PatchClient("http://localhost:9998/v3/endpoints/" + endpoint.getId()); JsonNode node = client.connect(wrapper); System.err.println(node.toString()); JsonNode endpointJ = node.get("endpoint"); assertEquals(endpoint.getId(), endpointJ.get("id").asText()); assertEquals(endpoint.getName(), endpointJ.get("name").asText()); assertEquals(endpoint.getInterfaceType(), endpointJ.get("interface").asText()); assertEquals(endpoint.getServiceid(), endpointJ.get("service_id").asText()); assertEquals(endpoint.getUrl(), endpointJ.get("url").asText()); }
From source file:eu.cloudwave.wp5.feedbackhandler.rest.JsonRestClientImplTest.java
private void assertResponseOk(final JsonNode actualResponse) throws JsonProcessingException, IOException { final JsonNode expectedResponse = new ObjectMapper().readTree(responseStub); assertThat(actualResponse.toString()).isEqualTo(expectedResponse.toString()); }
From source file:com.ericsson.eiffel.remrem.publish.service.EventTemplateHandler.java
private JsonNode jsonPathHandlerDelete(JsonNode updatedJson, String jsonkey) { updatedJson = JsonPath.using(configuration).parse(updatedJson.toString()).delete(jsonkey).json(); return updatedJson; }
From source file:com.mapr.synth.samplers.RandomWalkSampler.java
@SuppressWarnings("UnusedDeclaration") public void setS(JsonNode value) throws IOException { if (value.isObject()) { sd = FieldSampler.newSampler(value.toString()); } else {/* w w w .j ava 2 s. c o m*/ this.sd = constant(value.asDouble()); } init(); }
From source file:com.infinities.keystone4j.admin.v3.policy.PolicyV3ResourceTest.java
@Test public void testUpdatePolicy() throws ClientProtocolException, IOException { String policyid = this.policy.getId(); Policy policyUpdated = new Policy(); policyUpdated.setUserId("e7912c2225e84ac5905d8cf0b5040a6f"); policyUpdated.setType("newType"); policyUpdated.getBlob().put("default", true); PolicyWrapper wrapper = new PolicyWrapper(policyUpdated); String json = JsonUtils.toJson(wrapper, Views.Advance.class); System.err.println(json);//from ww w . j av a2 s .com PatchClient client = new PatchClient("http://localhost:9998/v3/policies/" + policyid); JsonNode node = client.connect(wrapper); System.err.println(node.toString()); JsonNode policyJ = node.get("policy"); assertEquals(policyid, policyJ.get("id").asText()); assertEquals(policyUpdated.getType(), policyJ.get("type").asText()); assertEquals(policyUpdated.getUserId(), policyJ.get("user_id").asText()); assertEquals(policy.getProjectId(), policyJ.get("project_id").asText()); assertTrue(policyJ.get("blob").hasNonNull("default")); assertEquals(policyUpdated.getBlob().get("default"), policyJ.get("blob").get("default").asBoolean()); assertNotNull(policyJ.get("links")); assertNotNull(policyJ.get("links").get("self").asText()); }
From source file:ymanv.forex.provider.impl.Yahoo.java
@Override public List<RateEntity> getRates() throws IOException { String response = handler.sendGet(URL); try {// ww w. j av a 2 s . com response = clean(response); CollectionType listType = mapper.getTypeFactory().constructCollectionType(List.class, YahooResource.class); JsonNode node = mapper.readTree(response).get("list").get("resources"); List<YahooResource> model = mapper.readValue(node.toString(), listType); List<RateEntity> rates = new ArrayList<>(); for (YahooResource o : model) { YahooFields yf = o.getResource().getFields(); String symbol = yf.getSymbol(); if (USD.equals(symbol)) { continue; } rates.add(new RateEntity(USD, symbol, yf.getPrice(), yf.getUtctime())); } return rates; } catch (Exception e) { LOG.error("Response: {}", StringUtils.toOneLine(response)); throw e; } }
From source file:com.redhat.lightblue.crud.ldap.ITCaseLdapCRUDController_Objects_Test.java
@Test public void test1PersonWithAddress_Insert() throws Exception { Response response = lightblueFactory.getMediator().insert(createRequest_FromResource(InsertionRequest.class, "./crud/insert/person-with-address-insert-single.json")); assertNotNull(response);// ww w . j av a2 s .co m assertNoErrors(response); assertNoDataErrors(response); assertEquals(1, response.getModifiedCount()); JsonNode entityData = response.getEntityData(); assertNotNull(entityData); JSONAssert.assertEquals("[{\"dn\":\"uid=john.doe," + BASEDB_USERS + "\"}]", entityData.toString(), false); }
From source file:org.obiba.mica.micaConfig.rest.CustomTranslationsResource.java
@PUT @Path("/import") @Consumes("application/json") public Response importTranslations(String translations, @QueryParam("merge") @DefaultValue("false") boolean merge) throws IOException { MicaConfig config = micaConfigService.getConfig(); JsonNode node = objectMapper.readTree(translations); List<String> locales = config.getLocalesAsString(); if (!config.hasTranslations()) { config.setTranslations(new LocalizedString()); }/*from www .j av a 2 s . c om*/ if (merge) { locales.forEach(l -> { JsonNode merged = micaConfigService.mergeJson(getTranslations(l), node.get(l)); config.getTranslations().put(l, merged.toString()); }); } else { locales.forEach(l -> config.getTranslations().put(l, node.get(l).toString())); } micaConfigService.save(config); return Response.ok().build(); }