List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString
public String toString()
From source file:com.wavemaker.commons.json.deserializer.HttpHeadersDeSerializer.java
@Override public HttpHeaders deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec codec = jp.getCodec();//from www . jav a 2s . c o m ObjectNode root = codec.readTree(jp); Map<String, Object> map = ((ObjectMapper) codec).readValue(root.toString(), new TypeReference<LinkedHashMap<String, Object>>() { }); HttpHeaders httpHeaders = new HttpHeaders(); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); if (value instanceof String) { httpHeaders.add(entry.getKey(), (String) entry.getValue()); } else if (value instanceof List) { httpHeaders.put(entry.getKey(), (List<String>) value); } } return httpHeaders; }
From source file:com.almende.pi5.lch.DERAgent.java
/** * Switch lamp./* w w w . ja v a 2 s .c o m*/ * * @param state * the state (1: on, 0: off) */ public void switchLamp(@Name("state") int state) { // var params = {LibraryName:'Lamp303',Parameters:{'Adres': 4221, // 'AanUit':1}}; final Params params = new Params(); final Params subparams = new Params(); params.put("LibraryName", "Lamp303"); subparams.put("Adres", 4221); subparams.put("AanUit", state); params.set("Parameters", subparams); try { call(URIUtil.create("ws://10.14.10.76:3000/agents/remoteGuy"), "ExecLibrary", params, new AsyncCallback<ObjectNode>() { /* (non-Javadoc) * @see com.almende.util.callback.AsyncCallback#onSuccess(java.lang.Object) */ @Override public void onSuccess(ObjectNode result) { LOG.info("Received result:" + result.toString()); } @Override public void onFailure(Exception exception) { LOG.log(Level.SEVERE, "Failed to call remoteGuy:", exception); } }); } catch (IOException e) { LOG.log(Level.SEVERE, "Failed to call remoteGuy:", e); } }
From source file:com.redhat.lightblue.query.SetExpression.java
/** * Parses a set expression using the given json object *///from www . j av a2 s . co m public static SetExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = null; if (node.has(UpdateOperator._add.toString())) { op = UpdateOperator._add; } else if (node.has(UpdateOperator._set.toString())) { op = UpdateOperator._set; } if (op != null) { ObjectNode arg = (ObjectNode) node.get(op.toString()); List<FieldAndRValue> list = new ArrayList<>(); for (Iterator<Map.Entry<String, JsonNode>> itr = arg.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> entry = itr.next(); Path field = new Path(entry.getKey()); RValueExpression rvalue = RValueExpression.fromJson(entry.getValue()); list.add(new FieldAndRValue(field, rvalue)); } return new SetExpression(op, list); } } throw Error.get(QueryConstants.ERR_INVALID_SET_EXPRESSION, node.toString()); }
From source file:de.cubeisland.engine.core.webapi.TextWebSocketFrameEncoder.java
@Override protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { if (msg instanceof String) { ObjectNode node = objectMapper.createObjectNode(); node.put("desc", (String) msg); out.add(new TextWebSocketFrame(node.toString())); } else if (msg instanceof JsonNode) { out.add(new TextWebSocketFrame(msg.toString())); } else {//w w w . jav a2 s . c om out.add(msg); } }
From source file:com.sqs.tq.fdc.TemplateReporter.java
@Override public void report(ObjectNode reportData) { try {//from w w w . j a va 2s . c o m Map<String, String> data = new HashMap<>(); data.put("data", reportData.toString()); template.process(data, writer); } catch (TemplateException | IOException e) { System.err.println("ERROR: " + e.getMessage()); } }
From source file:org.apache.olingo.fit.utils.Commons.java
public static InputStream getLinksAsJSON(final String entitySetName, final Map.Entry<String, Collection<String>> link) throws IOException { final ObjectNode links = new ObjectNode(JsonNodeFactory.instance); links.put(Constants.get(ConstantKey.JSON_ODATAMETADATA_NAME), Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + entitySetName + "/$links/" + link.getKey()); final ArrayNode uris = new ArrayNode(JsonNodeFactory.instance); for (String uri : link.getValue()) { final String absoluteURI; if (URI.create(uri).isAbsolute()) { absoluteURI = uri;/*from w w w . j a va 2 s . co m*/ } else { absoluteURI = Constants.get(ConstantKey.DEFAULT_SERVICE_URL) + uri; } uris.add(new ObjectNode(JsonNodeFactory.instance).put("url", absoluteURI)); } if (uris.size() == 1) { links.setAll((ObjectNode) uris.get(0)); } else { links.set("value", uris); } return IOUtils.toInputStream(links.toString(), Constants.ENCODING); }
From source file:org.openlmis.fulfillment.util.CustomSortDeserializerTest.java
@Test public void shouldDeserializeArraySort() throws IOException { ObjectMapper mapper = new ObjectMapper(); ObjectNode order = mapper.createObjectNode(); order.put("direction", "DESC"); order.put("property", "startDate"); order.put("ignoreCase", false); order.put("nullHandling", "NATIVE"); order.put("ascending", false); order.put("descending", true); ArrayNode arrayNode = mapper.createArrayNode(); arrayNode.add(order);//www. ja v a2 s . com ObjectNode testObject = mapper.createObjectNode(); testObject.set("sort", arrayNode); Sort sort = deserialize(testObject.toString()); assertEquals(Sort.Direction.DESC, sort.getOrderFor("startDate").getDirection()); }
From source file:org.ow2.chameleon.everest.impl.TestParameterToBeanSupport.java
@Test public void testBeaninificationWithNestedBean() { ObjectNode nested = objectMapper.createObjectNode().put("message", "a message").put("count", 1); nested.putArray("names").add("a").add("b").add("c"); ObjectNode node = objectMapper.createObjectNode().put("name", "clement").put("id", 1); node.put("bean", nested); System.out.println(node.toString()); DefaultRequest request = new DefaultRequest(Action.READ, Path.from("/foo"), new ImmutableMap.Builder<String, String>().put("test", node.toString()).build()); AnotherBean bean = request.get("test", AnotherBean.class); assertThat(bean.getId()).isEqualTo(1); assertThat(bean.getName()).isEqualTo("clement"); assertThat(bean.getBean().getCount()).isEqualTo(1); assertThat(bean.getBean().getMessage()).isEqualTo("a message"); assertThat(bean.getBean().getNames()).contains("a").contains("b").contains("c"); }
From source file:com.enitalk.opentok.OpentokCallback.java
@RequestMapping(method = RequestMethod.POST) @ResponseBody/* ww w . j a va 2 s. co m*/ public void verify(@RequestBody ObjectNode json) throws JsonProcessingException { try { logger.info("Tokbox came {}", json); rabbit.send("tokbox", MessageBuilder.withBody(json.toString().getBytes()).build()); } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRecordCreatingStep.java
private String createAppRecordBody(String spaceGuid, String appName) { ObjectMapper mapper = new ObjectMapper(); ObjectNode requestBody = mapper.createObjectNode(); requestBody.put("name", appName); requestBody.put("space_guid", spaceGuid); return requestBody.toString(); }