List of usage examples for com.fasterxml.jackson.databind.node ArrayNode toString
public String toString()
From source file:com.glaf.core.web.rest.MxTreeModelResource.java
@GET @POST/*from ww w .jav a 2 s. c o m*/ @Path("/subJson") @ResponseBody @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public byte[] subJson(@Context HttpServletRequest request) { String nodeCode = request.getParameter("nodeCode"); Long nodeId = RequestUtils.getLong(request, "id"); logger.debug(RequestUtils.getParameterMap(request)); List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>(); if (nodeId > 0) { TreeModel treeNode = treeModelService.getTreeModel(nodeId); if (treeNode != null) { treeModels = treeModelService.getSubTreeModels(treeNode.getId()); } } else if (StringUtils.isNotEmpty(nodeCode)) { TreeModel treeNode = treeModelService.getTreeModelByCode(nodeCode); if (treeNode != null) { treeModels = treeModelService.getSubTreeModels(treeNode.getId()); } } JacksonTreeHelper treeHelper = new JacksonTreeHelper(); ArrayNode responseJSON = treeHelper.getTreeArrayNode(treeModels); try { return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }
From source file:io.cloudslang.content.json.actions.MergeArrays.java
/** * This operation merge the contents of two JSON arrays. This operation does not modify either of the input arrays. * The result is the contents or array1 and array2, merged into a single array. The merge operation add into the result * the first array and then the second array. * * @param array1 The string representation of a JSON array object. * Arrays in JSON are comma separated lists of objects, enclosed in square brackets [ ]. * Examples: [1,2,3] or ["one","two","three"] or [{"one":1, "two":2}, 3, "four"] * @param array2 The string representation of a JSON array object. * Arrays in JSON are comma separated lists of objects, enclosed in square brackets [ ]. * Examples: [1,2,3] or ["one","two","three"] or [{"one":1, "two":2}, 3, "four"] * @return a map containing the output of the operation. Keys present in the map are: * <p/>/*from w w w.j a v a 2 s .co m*/ * <br><br><b>returnResult</b> - This will contain the string representation of the new JSON array with the contents * of array1 and array2. * <br><b>exception</b> - In case of success response, this result is empty. In case of failure response, * this result contains the java stack trace of the runtime exception. * <br><br><b>returnCode</b> - The returnCode of the operation: 0 for success, -1 for failure. */ @Action(name = "Merge Arrays", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array1, @Param(value = Constants.InputNames.ARRAY, required = true) String array2) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array1)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, exceptionValue, new Exception(exceptionValue)); } if (StringUtilities.isBlank(array2)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY2_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, new Exception(exceptionValue)); } JsonNode jsonNode1; JsonNode jsonNode2; ObjectMapper mapper = new ObjectMapper(); try { jsonNode1 = mapper.readTree(array1); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY1_MESSAGE + array1; return populateResult(returnResult, value, exception); } try { jsonNode2 = mapper.readTree(array2); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY2_MESSAGE + array2; return populateResult(returnResult, value, exception); } final String result; if (jsonNode1 instanceof ArrayNode && jsonNode2 instanceof ArrayNode) { final ArrayNode asJsonArray1 = (ArrayNode) jsonNode1; final ArrayNode asJsonArray2 = (ArrayNode) jsonNode2; final ArrayNode asJsonArrayResult = new ArrayNode(mapper.getNodeFactory()); asJsonArrayResult.addAll(asJsonArray1); asJsonArrayResult.addAll(asJsonArray2); result = asJsonArrayResult.toString(); } else { result = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE + array1 + ARRAY2_MESSAGE + array2; return populateResult(returnResult, new Exception(result)); } return populateResult(returnResult, result, null); }
From source file:com.enitalk.controllers.youtube.BotAware.java
public void sendMessages(ArrayNode msg) throws IOException, ExecutionException { String auth = botAuth();// w w w . ja va 2s. co m String tagResponse = Request.Post(env.getProperty("bot.sendMessage")) .addHeader("Authorization", "Bearer " + auth) .bodyString(msg.toString(), ContentType.APPLICATION_JSON).socketTimeout(20000).connectTimeout(5000) .execute().returnContent().asString(); logger.info("SendMsg sent to a bot {}, response {}", msg, tagResponse); }
From source file:org.opendaylight.sfc.sbrest.json.SffExporterFactory.java
@Override public String exportJsonNameOnly(DataObject dataObject) { String ret = null;/*from w ww . ja va 2 s. c om*/ if (dataObject instanceof ServiceFunctionForwarder) { ServiceFunctionForwarder obj = (ServiceFunctionForwarder) dataObject; ObjectNode node = mapper.createObjectNode(); node.put(_NAME, obj.getName().getValue()); ArrayNode sffArray = mapper.createArrayNode(); sffArray.add(node); ret = "{\"" + _SERVICE_FUNCTION_FORWARDER + "\":" + sffArray.toString() + "}"; } else { throw new IllegalArgumentException("Argument is not an instance of ServiceFunctionForwarder"); } return ret; }
From source file:ws.wamp.jawampa.transport.netty.WampDeserializationHandler.java
@Override protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out) throws Exception { if (readState != ReadState.Reading) return;/*from ww w .j a v a 2s. co m*/ ObjectMapper objectMapper = serialization.getObjectMapper(); if (frame instanceof TextWebSocketFrame) { // Only want Text frames when text subprotocol if (!serialization.isText()) throw new IllegalStateException("Received unexpected TextFrame"); TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; // If we receive an invalid frame on of the following functions will throw // This will lead Netty to closing the connection ArrayNode arr = objectMapper.readValue(new ByteBufInputStream(textFrame.content()), ArrayNode.class); if (logger.isDebugEnabled()) { logger.debug("Deserialized Wamp Message: {}", arr.toString()); } WampMessage recvdMessage = WampMessage.fromObjectArray(arr); out.add(recvdMessage); } else if (frame instanceof BinaryWebSocketFrame) { // Only want Binary frames when binary subprotocol if (serialization.isText()) throw new IllegalStateException("Received unexpected BinaryFrame"); BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame; // If we receive an invalid frame on of the following functions will throw // This will lead Netty to closing the connection ArrayNode arr = objectMapper.readValue(new ByteBufInputStream(binaryFrame.content()), ArrayNode.class); if (logger.isDebugEnabled()) { logger.debug("Deserialized Wamp Message: {}", arr.toString()); } WampMessage recvdMessage = WampMessage.fromObjectArray(arr); out.add(recvdMessage); } else if (frame instanceof PongWebSocketFrame) { // System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { // System.out.println("WebSocket Client received closing"); readState = ReadState.Closed; } }
From source file:com.activiti.service.activiti.ProcessInstanceService.java
public void createVariable(ServerConfig serverConfig, String processInstanceId, ObjectNode objectNode) { URIBuilder builder = clientUtil// w w w. j a v a 2 s. com .createUriBuilder(MessageFormat.format(RUNTIME_PROCESS_INSTANCE_VARIABLES, processInstanceId)); HttpPost post = clientUtil.createPost(builder, serverConfig); ArrayNode variablesNode = objectMapper.createArrayNode(); variablesNode.add(objectNode); post.setEntity(clientUtil.createStringEntity(variablesNode.toString())); clientUtil.executeRequest(post, serverConfig, 201); }
From source file:com.glaf.base.modules.sys.rest.SysDictoryResource.java
@GET @POST/* w w w .jav a 2s . c om*/ @Path("/treeJson") @ResponseBody @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public byte[] treeJson(@Context HttpServletRequest request) { String nodeCode = request.getParameter("nodeCode"); List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>(); if (StringUtils.isNotEmpty(nodeCode)) { TreeModel treeModel = sysTreeService.getSysTreeByCode(nodeCode); if (treeModel != null) { SysTreeQuery query = new SysTreeQuery(); Map<String, Object> params = RequestUtils.getParameterMap(request); Tools.populate(query, params); // query.setParentId(treeModel.getId()); List<SysTree> trees = sysTreeService.getDictorySysTrees(query); if (trees != null && !trees.isEmpty()) { for (SysTree tree : trees) { treeModels.add(tree); } } } } JacksonTreeHelper treeHelper = new JacksonTreeHelper(); ArrayNode responseJSON = treeHelper.getTreeArrayNode(treeModels); try { return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }
From source file:com.glaf.base.modules.sys.rest.SysApplicationResource.java
@GET @POST// www . j ava2 s . co m @Path("/treeJson") @ResponseBody @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public byte[] treeJson(@Context HttpServletRequest request) { String nodeCode = request.getParameter("nodeCode"); List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>(); if (StringUtils.isNotEmpty(nodeCode)) { TreeModel treeModel = sysTreeService.getSysTreeByCode(nodeCode); if (treeModel != null) { SysTreeQuery query = new SysTreeQuery(); Map<String, Object> params = RequestUtils.getParameterMap(request); Tools.populate(query, params); // query.setParentId(treeModel.getId()); List<SysTree> trees = sysTreeService.getApplicationSysTrees(query); if (trees != null && !trees.isEmpty()) { for (SysTree tree : trees) { treeModels.add(tree); } } } } JacksonTreeHelper treeHelper = new JacksonTreeHelper(); ArrayNode responseJSON = treeHelper.getTreeArrayNode(treeModels); try { return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }
From source file:com.glaf.base.modules.sys.rest.SysTreeResource.java
@GET @POST//from w w w. j ava2 s. c o m @Path("/allTreeJson") @ResponseBody @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public byte[] allTreeJson(@Context HttpServletRequest request) { logger.debug("params:" + RequestUtils.getParameterMap(request)); List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>(); List<SysTree> trees = sysTreeService.getAllSysTreeList(); if (trees != null && !trees.isEmpty()) { for (SysTree tree : trees) { treeModels.add(tree); } } JacksonTreeHelper treeHelper = new JacksonTreeHelper(); ArrayNode array = treeHelper.getTreeArrayNode(treeModels); try { return array.toString().getBytes("UTF-8"); } catch (IOException e) { return array.toString().getBytes(); } }
From source file:com.glaf.base.modules.sys.rest.SysDepartmentResource.java
@GET @POST//from w w w . j a va2 s. co m @Path("/treeJson") @ResponseBody @Produces({ MediaType.APPLICATION_OCTET_STREAM }) public byte[] treeJson(@Context HttpServletRequest request) { String nodeCode = request.getParameter("nodeCode"); List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>(); if (StringUtils.isNotEmpty(nodeCode)) { TreeModel treeModel = sysTreeService.getSysTreeByCode(nodeCode); if (treeModel != null) { SysTreeQuery query = new SysTreeQuery(); Map<String, Object> params = RequestUtils.getParameterMap(request); Tools.populate(query, params); // query.setParentId(treeModel.getId()); List<SysTree> trees = sysTreeService.getDepartmentSysTrees(query); if (trees != null && !trees.isEmpty()) { for (SysTree tree : trees) { treeModels.add(tree); } } } } JacksonTreeHelper treeHelper = new JacksonTreeHelper(); ArrayNode responseJSON = treeHelper.getTreeArrayNode(treeModels); try { return responseJSON.toString().getBytes("UTF-8"); } catch (IOException e) { return responseJSON.toString().getBytes(); } }