List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:acromusashi.stream.example.ml.client.KMeansDrpcClient.java
/** * KMeans??DRPC???LOF??//from w w w . j a v a 2s .c o m * * @param drpcHost DRPC * @param drpcPort DRPC? * @param drpcFunction ???? * @param kmeansData KMeans * @return KMeans? * @throws DRPCExecutionException DRPC * @throws TException DRPC * @throws IOException ? */ public String sendRequest(String drpcHost, int drpcPort, String drpcFunction, String kmeansData) throws TException, DRPCExecutionException, IOException { DRPCClient client = new DRPCClient(drpcHost, drpcPort); String drpcResult = client.execute(drpcFunction, kmeansData); // ????????? // [["0.3230647,0.4288709,0.2918048,0.7904559,5", // "KmeansPoint[label=<null>,dataPoint={0.3230647,0.4288709,0.2918048,0.7904559,5.0}]", // "{\"dataPoint\":[0.3230647,0.4288709,0.2918048,0.7904559,5.0],\"centroidIndex\":2, // \"centroid\":[0.49254449862586597,0.29060293775519647,0.19902678114457303,0.7925079800808319,5.0],\"distance\":0.23759924945376112}"]] ObjectMapper mapper = new ObjectMapper(); JsonNode baseNode = mapper.readTree(drpcResult); String kmeanResultStr = baseNode.get(0).get(2).asText(); JsonNode kmeanResultTree = mapper.readTree(kmeanResultStr); return kmeanResultTree.toString(); }
From source file:easyrpc.client.serialization.jsonrpc.JSONCaller.java
@Override public Object deserializeResponse(Class returnType, byte[] response) { try {// ww w .ja v a 2 s. c o m ObjectNode resp = (ObjectNode) MAPPER.readTree(response); String jsonversion = resp.get("jsonrpc").textValue(); if (!"2.0".equals(jsonversion)) { throw new SerializationException( "'jsonrpc' value must be '2.0' and actually is '" + jsonversion + "'"); } // todo: differentiate exceptions as defined in the interfaces if (resp.has("error")) { JsonNode error = resp.get("error"); throw new RemoteMethodException(error.toString()); } // System.out.println("resp.get(\"result\").toString() = " + resp.toString()); if (!returnType.equals(Void.class) && !returnType.equals(void.class)) { Object result = MAPPER.treeToValue(resp.get("result"), returnType); return result; } else { return null; } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.gravidence.gravifon.db.ViewQueryArguments.java
/** * Adds <code>startkey</code> query argument. * // www . j a v a 2 s.c o m * @param value query argument value * @return reference to this object */ public ViewQueryArguments addStartKey(JsonNode value) { arguments.put("startkey", value.toString()); return this; }
From source file:com.redhat.lightblue.query.SetExpressionTest.java
/** * Test of toJson method, of class SetExpression. *//*from w w w.j a v a2s . c o m*/ @Test public void testToJson() { List<FieldAndRValue> list = new ArrayList<>(); FieldAndRValue fav = new FieldAndRValue(); fav.setField(Path.EMPTY); fav.setRValue(new RValueExpression(Path.EMPTY)); list.add(fav); SetExpression instance = null; instance = new SetExpression(UpdateOperator._set, list); JsonNode result = instance.toJson(); assertEquals("{\"$set\":{\"\":{\"$valueof\":\"\"}}}", result.toString()); }
From source file:com.infinities.keystone4j.admin.v3.service.ServiceResourceTest.java
@Test public void testUpdateService() throws JsonProcessingException, IOException { ServiceWrapper wrapper = new ServiceWrapper(service); service.setName("demo"); PatchClient client = new PatchClient("http://localhost:9998/v3/services/" + service.getId()); JsonNode node = client.connect(wrapper); System.err.println(node.toString()); JsonNode serviceJ = node.get("service"); assertEquals(service.getId(), serviceJ.get("id").asText()); assertEquals(service.getName(), serviceJ.get("name").asText()); assertEquals(service.getDescription(), serviceJ.get("description").asText()); assertEquals(service.getType(), serviceJ.get("type").asText()); }
From source file:com.dhenton9000.json.processing.FasterXMLJSONTests.java
@Test public void testModifiedTreeToString() throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode sampleTree = mapper.readTree(TEST_STRING); ObjectNode sampleObj = (ObjectNode) sampleTree; sampleObj.put("alpha", 99); assertEquals(sampleTree.toString(), "{\"alpha\":99,\"beta\":\"get a job\"}"); }
From source file:com.almende.eve.transport.http.embed.JettyLauncher.java
@Override public void add(final Servlet servlet, final URI servletPath, final ObjectNode config) throws ServletException { // TODO: config hierarchy... if (server == null) { if (config != null) { initServer((ObjectNode) config.get("jetty")); } else {//from w ww. j av a 2s .c om initServer(JOM.createObjectNode()); } } LOG.info("Registering servlet:" + servletPath.getPath()); ServletHolder sh = new ServletHolder(servlet); if (config.has("initParams")) { ArrayNode params = (ArrayNode) config.get("initParams"); for (JsonNode param : params) { LOG.warning("Setting init param:" + param.toString()); sh.setInitParameter(param.get("key").asText(), param.get("value").asText()); } } context.addServlet(sh, servletPath.getPath() + "*"); }
From source file:com.mockey.ui.JsonSchemaLoadSamplesServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final int index = RND.nextInt(SAMPLE_DATA_SIZE); final JsonNode ret = SAMPLE_DATA.get(index); final OutputStream out = resp.getOutputStream(); try {// www . j a va 2 s . c o m out.write(ret.toString().getBytes(Charset.forName("UTF-8"))); out.flush(); } finally { Closeables.closeQuietly(out); } }
From source file:io.gravitee.definition.jackson.datatype.plugins.resource.deser.ResourceDeserializer.java
@Override public Resource deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); Resource resource = new Resource(); final JsonNode nameNode = node.get("name"); if (nameNode != null) { resource.setName(nameNode.asText()); } else {//from w w w .j av a 2 s .co m throw ctxt.mappingException("[resource] Name is required"); } final JsonNode typeNode = node.get("type"); if (typeNode != null) { resource.setType(typeNode.asText()); } else { throw ctxt.mappingException("[resource] Type is required"); } final JsonNode configurationNode = node.get("configuration"); if (configurationNode != null) { resource.setConfiguration(configurationNode.toString()); } else { throw ctxt.mappingException("[resource] Configuration is required"); } final JsonNode enabledNode = node.get("enabled"); if (enabledNode != null) { resource.setEnabled(enabledNode.asBoolean(true)); } else { resource.setEnabled(true); } return resource; }
From source file:com.microsoft.azure.serializer.CloudErrorDeserializer.java
@Override public CloudError deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode topNode = p.readValueAsTree(); if (topNode == null) { return null; }//from w w w .java 2 s .c o m JsonNode errorNode = topNode.get("error"); if (errorNode == null) { return null; } JsonParser parser = new JsonFactory().createParser(errorNode.toString()); parser.setCodec(mapper); return parser.readValueAs(CloudError.class); }