List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:io.pivio.server.document.SearchApiTest.java
private ArrayNode executeSearch(JsonNode searchQuery, String fieldParameter, String sortParameter) throws IOException { String searchParameter = URLEncoder.encode(searchQuery.toString(), "UTF-8"); if (StringUtils.isNotEmpty(fieldParameter)) { searchParameter += "&fields=" + fieldParameter; }/* w w w. j a v a 2 s . co m*/ if (StringUtils.isNotEmpty(sortParameter)) { searchParameter += "&sort=" + sortParameter; } try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) { HttpGet request = new HttpGet("http://localhost:" + port + "/document?query=" + searchParameter); request.setHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE); HttpResponse response = httpClient.execute(request); return (ArrayNode) objectMapper.readTree(EntityUtils.toString(response.getEntity(), "UTF-8")); } }
From source file:com.Anderson.example.games.tanc.GameplayFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d("I", "Quase la"); View v = inflater.inflate(R.layout.fragment_gameplay, container, false); mTimer = (TextView) v.findViewById(R.id.timer_field); Log.d("I", mTimer.getText().toString() + "WW"); ObjectMapper mapper = new ObjectMapper(); mCurrentQuestion = 0;/*from ww w . ja va2 s . c o m*/ Log.d("I", "Quase la2"); try { InputStream myFile = getActivity().getAssets().open("texts/" + mListener.onQuestionaryAsk()); Log.d("I", "Quase la3"); Base64InputStream bs = new Base64InputStream(myFile, 80); JsonNode actualObj = mapper.readTree(bs); AssignToQuestionary(actualObj); Log.d("I", actualObj.toString()); } catch (IOException e) { e.printStackTrace(); } if (mListener.onQuestionaryAsk().contains("Timer")) { SetTimer(); myCDT.start(); isTimer = true; } if (mListener.onQuestionaryAsk().contains("Multiple")) { isMultiple = true; mRequestedScore = 20; TextView scoreInput = ((TextView) getActivity().findViewById(R.id.score_text)); if (scoreInput != null) scoreInput.setText("Score: " + 20); } ManageButtons(v); return v; }
From source file:org.jboss.aerogear.sync.client.netty.SyncClientHandler.java
@Override protected void channelRead0(final ChannelHandlerContext ctx, final WebSocketFrame frame) throws Exception { if (frame instanceof CloseWebSocketFrame) { logger.debug("Received closeFrame"); ctx.close();//from w ww . j a v a 2s . co m return; } if (frame instanceof TextWebSocketFrame) { logger.info("TextWebSocketFrame: " + ((TextWebSocketFrame) frame).text()); final JsonNode json = JsonMapper.asJsonNode(((TextWebSocketFrame) frame).text()); logger.info("json: " + json); switch (MessageType.from(json.get("msgType").asText())) { case PATCH: final PatchMessage<S> serverPatchMessage = syncEngine.patchMessageFromJson(json.toString()); logger.info("Edits: " + serverPatchMessage); patch(serverPatchMessage); break; case UNKNOWN: unknownMessageType(ctx, json); break; } } else { ctx.fireChannelRead(frame); } }
From source file:org.up4j.APITest.java
/** * Test of getUserSettings method, of class API. *///w ww. j a v a 2s . co m @Test public void testGetSettings() throws Exception { System.out.println("getSettings"); UserSettings settings2 = api.getUserSettings(); assertNotNull(settings2); JsonNode dataNode = jsonResponseHolder.getJson().get("data"); System.out.println(dataNode.toString()); System.out.println(OBJECT_MAPPER.writeValueAsString(settings2)); assertTrue(dataNode.get("basic_info") .equals(OBJECT_MAPPER.convertValue(settings2.getBasicInfo(), JsonNode.class))); assertTrue(dataNode.get("smart_alarm") .equals(OBJECT_MAPPER.convertValue(settings2.getSmartAlarm(), JsonNode.class))); assertTrue( dataNode.get("up_goals").equals(OBJECT_MAPPER.convertValue(settings2.getGoals(), JsonNode.class))); assertTrue(dataNode.get("power_nap") .equals(OBJECT_MAPPER.convertValue(settings2.getPowerNap(), JsonNode.class))); assertTrue(dataNode.get("active_alert") .equals(OBJECT_MAPPER.convertValue(settings2.getActiveAlert(), JsonNode.class))); }
From source file:com.redhat.lightblue.crud.ldap.ITCaseLdapCRUDControllerTest.java
@Test public void series2_phase1_Department_InsertWithRoles() throws Exception { String insert = AbstractJsonNodeTest.loadResource("./crud/insert/department-insert-template.json") .replaceFirst("#cn", "Marketing").replaceFirst("#description", "Department devoted to Marketing") .replaceFirst("#members", "\"" + StringUtils.join( Arrays.asList("cn=John Doe," + BASEDB_USERS, "cn=Jane Doe," + BASEDB_USERS), "\",\"") + "\""); InsertionRequest insertRequest = createRequest_FromJsonString(InsertionRequest.class, insert); insertRequest.setClientId(new FakeClientIdentification("fakeUser", "admin")); Response response = getLightblueFactory().getMediator().insert(insertRequest); assertNotNull(response);/*from w ww . ja va2 s . c om*/ assertNoErrors(response); assertNoDataErrors(response); assertEquals(1, response.getModifiedCount()); JsonNode entityData = response.getEntityData(); assertNotNull(entityData); JSONAssert.assertEquals("[{\"dn\":\"cn=Marketing," + BASEDB_DEPARTMENTS + "\"}]", entityData.toString(), true); }
From source file:org.eel.kitchen.jsonschema.uri.URIManagerTest.java
@Test public void URIRedirectionIsFollowed() throws IOException, JsonSchemaException { /*/*from w ww . j a v a2 s . c o m*/ * The content we return */ final JsonNode expected = JsonNodeFactory.instance.objectNode().put("hello", "world"); final InputStream sampleStream = new ByteArrayInputStream(expected.toString().getBytes()); /* * We need to build both the source URI and destination URI. As they are * both transformed to valid JSON References internally, we also build * JsonRef-compatible URIs (ie, with a fragment, even empty). * * The user, however, may supply URIs which are not JsonRef-compatible. */ final String from = "http://some.site/schema.json"; final String to = "foo://real/location.json"; manager.addRedirection(from, to); final URI source = JsonRef.fromString(from).getLocator(); final URI target = JsonRef.fromString(to).getLocator(); /* * Build another mock for the original source URI protocol, make it * return the same thing as the target URI. Register both downloaders. */ final URIDownloader httpMock = mock(URIDownloader.class); when(httpMock.fetch(source)).thenReturn(sampleStream); manager.registerScheme("http", httpMock); when(mock.fetch(target)).thenReturn(sampleStream); manager.registerScheme("foo", mock); /* * Get the original source... */ final JsonNode actual = manager.getContent(source); /* * And verify that it has been downloaded from the target, not the * source */ verify(httpMock, never()).fetch(any(URI.class)); verify(mock).fetch(target); /* * Finally, ensure the correctness of the downloaded content. */ assertEquals(actual, expected); }
From source file:nosqltools.JSONUtilities.java
public JsonNode convertJArr(JsonNode jNode) { ObjectMapper mapper = new ObjectMapper(); JsonNode convertedNode = null;/* w ww . j a v a2s. c o m*/ try { String nodeText = jNode.toString(); //convert to array by simply adding square bracket before and after the json object convertedNode = mapper.readTree("[" + nodeText + "]"); } catch (JsonParseException | JsonGenerationException | JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return convertedNode; }
From source file:com.almende.eve.state.AbstractState.java
/** * Loc put./* ww w. java2s.c o m*/ * * @param key the key * @param value the value * @return the json node */ public JsonNode locPut(final String key, final JsonNode value) { LOG.warning( "Warning, this type of State can't store JsonNodes, only Serializable objects. This JsonNode is stored as string."); locPut(key, value.toString()); return value; }
From source file:com.servioticy.dispatcher.bolts.ActuationDispatcherBolt.java
public void execute(Tuple input) { try {//w w w . j a va 2s . c om String sourceSOId; String actionId; String actionName; JsonNode actuation = this.mapper.readTree(input.getStringByField("action")); sourceSOId = input.getStringByField("soid"); actionId = input.getStringByField("id"); actionName = input.getStringByField("name"); Log.info("received actuation\n\t\t" + "action: " + actuation.toString() + "\n\t\t" + "soid: " + sourceSOId + "\n\t\t" + "name: " + actionName + "\n\t\t" + "id: " + actionId); if (!publisher.isConnected()) { publisher.connect(dc.actionsPubUser, dc.actionsPubPassword); } publisher.publishMessage(sourceSOId + "/actions", actuation.toString()); LOG.info("Actuation request pubished on topic " + sourceSOId + "/actions"); LOG.info("Actuation message contents: " + actuation.toString()); } catch (Exception e) { LOG.error("FAIL", e); collector.fail(input); return; } collector.ack(input); }