List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put
public ObjectNode put(String paramString1, String paramString2)
From source file:controllers.api.v1.Metric.java
public static Result getMetricByID(int id) { String user = session("user"); models.Metric metric = MetricsDAO.getMetricByID(id, user); ObjectNode result = Json.newObject(); if (metric != null) { result.put("status", "ok"); result.set("metric", Json.toJson(metric)); } else {//from w w w.j a v a 2 s .c o m result.put("status", "error"); result.put("message", "record not found"); } return ok(result); }
From source file:net.hamnaberg.json.Property.java
private static ObjectNode makeObject(String name, Optional<String> prompt) { ObjectNode node = JsonNodeFactory.instance.objectNode(); node.put("name", name); prompt.ifPresent(value -> node.put("prompt", value)); return node;//from www . jav a2 s .c o m }
From source file:controllers.api.v1.Metric.java
public static Result unwatchMetric(int id, int watchId) { ObjectNode result = Json.newObject(); if (MetricsDAO.unwatch(watchId)) { result.put("status", "success"); } else {//from ww w .j a va 2s .c o m result.put("status", "failed"); } return ok(result); }
From source file:net.hamnaberg.json.Item.java
public static Item create(Optional<URI> href, Iterable<Property> properties, List<Link> links) { ObjectNode node = JsonNodeFactory.instance.objectNode(); href.ifPresent(uri -> node.put("href", uri.toString())); if (!Iterables.isEmpty(properties)) { node.set("data", StreamSupport.stream(properties.spliterator(), false).map(Extended::asJson) .collect(JsonNodeFactory.instance::arrayNode, ArrayNode::add, ArrayNode::addAll)); }//from ww w . j a va 2s . c o m if (!Iterables.isEmpty(links)) { node.set("links", StreamSupport.stream(links.spliterator(), false).map(Extended::asJson) .collect(JsonNodeFactory.instance::arrayNode, ArrayNode::add, ArrayNode::addAll)); } return new Item(node); }
From source file:easyrpc.server.serialization.jsonrpc.JSONCallee.java
private static final void addResult(ObjectNode json, Object value) { switch (value.getClass().getName()) { case "java.lang.Integer": case "int": json.put("result", (Integer) value); break;// w w w. j av a 2s . c o m case "java.lang.Long": case "long": json.put("result", (Long) value); break; case "java.lang.Character": case "char": json.put("result", (java.lang.Character) value); break; case "java.lang.Void": case "void": throw new IllegalArgumentException("A parameter cannot be of void type"); case "java.lang.Float": case "float": json.put("result", (Float) value); break; case "java.lang.Double": case "double": json.put("result", (Double) value); break; case "java.lang.String": json.put("result", (String) value); break; default: // map an object ObjectNode retPojo = json.putPOJO("result", MAPPER.valueToTree(value)); // System.out.println("retPojo.toString() = " + retPojo.toString()); } }
From source file:models.Friend.java
public static List<Friend> all() { ObjectNode jsonData = Json.newObject(); jsonData.put("email", session().get("email")); JsonNode response = UserService.getUserByEmail(jsonData); Application.sessionMsg(response);// ww w.ja va 2s . co m String userID = response.path("userId").asText(); JsonNode allfriends = UserService.getAllFriends(userID); Iterator<JsonNode> it = allfriends.get("friends").iterator(); List<Friend> friends = new ArrayList<Friend>(); while (it.hasNext()) { JsonNode now = it.next(); friends.add(new Friend(now.get("userName").asText(), now.get("userId").asInt())); } /* JsonNode postsNode = APICall .callAPI(GET_POSTS_CALL); if (postsNode == null || postsNode.has("error") || !postsNode.isArray()) { return posts; } for (int i = 0; i < postsNode.size(); i++) { JsonNode json = postsNode.path(i); Post post = new Post(json.path("image").asText(),json.path("text").asText(),json.path("title").asText()); posts.add(post); } */ return friends; }
From source file:models.Friend.java
public static List<Friend> allSubscribe() { ObjectNode jsonData = Json.newObject(); jsonData.put("email", session().get("email")); JsonNode response = UserService.getUserByEmail(jsonData); Application.sessionMsg(response);//from w w w .j av a 2 s. com String userID = response.path("userId").asText(); JsonNode allfriends = UserService.getAllFriends(userID); Iterator<JsonNode> it = allfriends.get("subscribeUsers").iterator(); List<Friend> friends = new ArrayList<Friend>(); while (it.hasNext()) { JsonNode now = it.next(); friends.add(new Friend(now.get("userName").asText(), now.get("userId").asInt())); } /* JsonNode postsNode = APICall .callAPI(GET_POSTS_CALL); if (postsNode == null || postsNode.has("error") || !postsNode.isArray()) { return posts; } for (int i = 0; i < postsNode.size(); i++) { JsonNode json = postsNode.path(i); Post post = new Post(json.path("image").asText(),json.path("text").asText(),json.path("title").asText()); posts.add(post); } */ return friends; }
From source file:securesocial.core.java.SecureSocial.java
/** * Generates the error json required for ajax calls calls when the * user is not authenticated/*w w w . j a v a 2s.c o m*/ * * @return */ private static ObjectNode ajaxCallNotAuthenticated() { ObjectNode result = Json.newObject(); result.put("error", "Credentials required"); return result; }
From source file:securesocial.core.java.SecureSocial.java
/** * Generates the error json required for ajax calls calls when the * user is not authorized to execute the action * * @return/*from ww w . ja v a 2 s .co m*/ */ private static ObjectNode ajaxCallNotAuthorized() { ObjectNode result = Json.newObject(); result.put("error", "Not authorized"); return result; }
From source file:com.github.fge.jsonschema.syntax.checkers.SyntaxCheckersTest.java
private static SchemaTree treeFromValue(final String keyword, final JsonNode node) { final ObjectNode schema = JacksonUtils.nodeFactory().objectNode(); schema.put(keyword, node); return new CanonicalSchemaTree(schema); }