List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add
public ArrayNode add(JsonNode paramJsonNode)
From source file:net.hamnaberg.json.Property.java
private static ArrayNode toArray(List<Value> list) { ArrayNode array = JsonNodeFactory.instance.arrayNode(); for (Value value : list) { array.add(value.asJson()); }//from w w w . j av a2 s. c o m return array; }
From source file:mobile.service.UserSettingService.java
/** * ?SNS//from ww w.java 2s. com * * @return */ public static ServiceVOResult<CommonVO> getConnectedSNS() { User user = User.getFromSession(Context.current().session()); Map<String, UserOAuth> userOAuthMap = UserOAuthService.getValidByUserId(user.id); ArrayNode sns = Json.newObject().arrayNode(); for (Map.Entry<String, UserOAuth> e : userOAuthMap.entrySet()) { sns.add(e.getKey()); } CommonVO vo = CommonVO.create(); vo.set("sns", sns); ServiceVOResult<CommonVO> result = ServiceVOResult.success(); result.setVo(vo); return result; }
From source file:controllers.MetaController.java
private static JsonNode getConfigNode(final Object element) { if (element instanceof Configuration) { final Configuration config = (Configuration) element; final ObjectNode node = JsonNodeFactory.instance.objectNode(); for (final Map.Entry<String, ConfigValue> entry : config.entrySet()) { put(node, entry.getKey(), entry.getValue()); }// w w w . ja v a 2s.c om return node; } else if (element instanceof String) { final String config = (String) element; return JsonNodeFactory.instance.textNode(config); } else if (element instanceof Integer) { final Integer integer = (Integer) element; return JsonNodeFactory.instance.numberNode(integer); } else if (element instanceof Double) { final Double d = (Double) element; return JsonNodeFactory.instance.numberNode(d); } else if (element instanceof ArrayList) { final ArrayNode arr = JsonNodeFactory.instance.arrayNode(); @SuppressWarnings("unchecked") final ArrayList<Object> list = (ArrayList<Object>) element; for (final Object o : list) { arr.add(getConfigNode(o)); } return arr; } return JsonNodeFactory.instance.textNode("UNKNOWN TYPE: " + element.getClass().getCanonicalName()); }
From source file:com.linecorp.armeria.server.grpc.GrpcDocServiceTest.java
private static void addExamples(JsonNode json) { json.get("services").forEach(service -> { final String serviceName = service.get("name").textValue(); // Add the method-specific examples. service.get("methods").forEach(method -> { final String methodName = method.get("name").textValue(); final ArrayNode exampleRequests = (ArrayNode) method.get("exampleRequests"); if (TestServiceGrpc.SERVICE_NAME.equals(serviceName) && "UnaryCall".equals(methodName)) { exampleRequests .add("{\n" + " \"payload\": {\n" + " \"body\": \"d29ybGQ=\"\n" + " }\n" + '}'); }/* w w w . java 2 s . c om*/ }); }); }
From source file:org.apache.asterix.api.http.server.ResultUtil.java
public static ObjectNode getErrorResponse(int errorCode, String errorMessage, String errorSummary, String errorStackTrace) { ObjectMapper om = new ObjectMapper(); ObjectNode errorResp = om.createObjectNode(); ArrayNode errorArray = om.createArrayNode(); errorArray.add(errorCode); errorArray.add(errorMessage);//from w ww.j a va2s . c o m errorResp.set("error-code", errorArray); if (!"".equals(errorSummary)) { errorResp.put("summary", errorSummary); } else { //parse exception errorResp.put("summary", errorMessage); } errorResp.put("stacktrace", errorStackTrace); return errorResp; }
From source file:com.nirmata.workflow.details.JsonSerializer.java
public static JsonNode newRunnableTaskDag(RunnableTaskDag runnableTaskDag) { ArrayNode tab = newArrayNode(); runnableTaskDag.getDependencies().forEach(taskId -> tab.add(taskId.getId())); ObjectNode node = newNode();/* ww w.j a v a 2s . c o m*/ node.put("taskId", runnableTaskDag.getTaskId().getId()); node.set("dependencies", tab); return node; }
From source file:com.marklogic.client.functionaltest.JavaApiBatchSuite.java
public static void createRESTUser(String usrName, String pass, String roleName) { try {/* w w w . jav a 2 s. c o m*/ DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002), new UsernamePasswordCredentials("admin", "admin")); HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/users?format=json"); ObjectMapper mapper = new ObjectMapper(); ObjectNode mainNode = mapper.createObjectNode(); // ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); mainNode.put("name", usrName); mainNode.put("description", "user discription"); mainNode.put("password", pass); childArray.add(roleName); mainNode.put("role", childArray); //System.out.println(type + mainNode.path("range-element-indexes").path("range-element-index").toString()); // System.out.println(mainNode.toString()); post.addHeader("Content-type", "application/json"); post.setEntity(new StringEntity(mainNode.toString())); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == 400) { System.out.println("User already exist or a bad create request"); } else if (respEntity != null) { // EntityUtils to get the response content String content = EntityUtils.toString(respEntity); System.out.println(content); } else { System.out.print("No Proper Response"); } } catch (Exception e) { // writing error to Log e.printStackTrace(); } }
From source file:com.nirmata.workflow.details.JsonSerializer.java
public static JsonNode newRunnableTask(RunnableTask runnableTask) { ArrayNode taskDags = newArrayNode(); runnableTask.getTaskDags().forEach(taskDag -> taskDags.add(newRunnableTaskDag(taskDag))); ObjectNode tasks = newNode();//www . j av a 2 s . co m runnableTask.getTasks().entrySet() .forEach(entry -> tasks.set(entry.getKey().getId(), newExecutableTask(entry.getValue()))); ObjectNode node = newNode(); node.set("taskDags", taskDags); node.set("tasks", tasks); node.put("startTimeUtc", runnableTask.getStartTimeUtc().format(DateTimeFormatter.ISO_DATE_TIME)); node.put("completionTimeUtc", runnableTask.getCompletionTimeUtc().isPresent() ? runnableTask.getCompletionTimeUtc().get().format(DateTimeFormatter.ISO_DATE_TIME) : null); node.put("parentRunId", runnableTask.getParentRunId().isPresent() ? runnableTask.getParentRunId().get().getId() : null); return node; }
From source file:com.ibm.watson.catalyst.corpus.tfidf.CorpusTfidf.java
private static ObjectNode printGoodWords(TermDocument d, TermCorpus c) { ObjectNode result = MAPPER.createObjectNode(); result.put("document", d.getContext(0)); WordFrequencyHashtable f = d.getFrequencies(); SortedArrayList<String> importantWords = new SortedArrayList<String>(); {/*from w ww. j a va 2 s . c o m*/ Iterator<String> words = f.sortedIterator(1); while (words.hasNext()) { String word = words.next(); //if (d.frequency(word) < 5) continue; importantWords.sortedAdd(word, tfidf(word, d, c)); } } SortedArrayList<String> wordList; switch (sortedBy) { case TFIDF: wordList = importantWords; break; case FREQ: wordList = new SortedArrayList<String>(); for (String word : importantWords) wordList.sortedAdd(word, f.get(word)); break; default: throw new IllegalStateException(); } ArrayNode wordNodes = MAPPER.createArrayNode(); for (String word : wordList) { ObjectNode wordNode = MAPPER.createObjectNode(); wordNode.put("string", word); wordNode.put("frequency", f.get(word)); wordNode.put("tfidf", tfidf(word, d, c)); wordNodes.add(wordNode); } result.set("words", wordNodes); return result; }
From source file:de.cubeisland.engine.core.util.McUUID.java
private static void getProfiles(List<Profile> profiles, LinkedList<String> players) { int amount = players.size(); CubeEngine.getLog().debug("Query UUID for: " + StringUtils.implode(",", players)); ArrayNode node = mapper.createArrayNode(); while (!players.isEmpty()) { ObjectNode criteria = mapper.createObjectNode(); criteria.put("name", players.poll()); criteria.put("agent", AGENT); node.add(criteria); }/*w w w . ja v a 2s. co m*/ int page = 1; try { CubeEngine.getLog().info("Query Mojang for {} UUIDs", amount); while (amount > 0) { int read = readProfilesFromInputStream(postQuery(node, page++).getInputStream(), profiles); if (read == 0) { CubeEngine.getLog().info("No Answer for {} players", amount); } else if (read != amount) { amount -= read; continue; } return; } } catch (IOException e) { CubeEngine.getLog().error(e, "Could not retrieve UUID for given names!"); } }