List of usage examples for com.fasterxml.jackson.databind ObjectMapper createArrayNode
@Override
public ArrayNode createArrayNode()
Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)
From source file:org.jolokia.client.request.J4pConnectionPoolingIntegrationTest.java
private String getJsonResponse(String message) { final ObjectMapper objectMapper = new ObjectMapper(); final ObjectNode node = objectMapper.createObjectNode(); final ArrayNode arrayNode = objectMapper.createArrayNode(); arrayNode.add("java.lang:type=Memory"); node.putArray("value").addAll(arrayNode); node.put("status", 200); node.put("timestamp", 1244839118); return node.toString(); }
From source file:com.evrythng.java.wrapper.mapping.ActionsDeserializer.java
@Override public Actions deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { ObjectMapper mapper = JSONUtils.OBJECT_MAPPER; JsonNode node = mapper.readTree(jp); if (node.isArray()) { return mapper.readValue(node.toString(), ActionsImpl.class); } else {/*from www . jav a2 s.co m*/ ArrayNode array = mapper.createArrayNode(); array.add(node); return mapper.readValue(array.toString(), ActionsImpl.class); } }
From source file:org.commonjava.indy.metrics.zabbix.api.IndyZabbixApi.java
public String getItem(String host, String item, String hostid) throws IOException { ObjectMapper mapper = new ObjectMapper(); ArrayNode groups = mapper.createArrayNode(); ObjectNode search = mapper.createObjectNode(); search.put("key_", item); Request getRequest = RequestBuilder.newBuilder().method("item.get").paramEntry("hostids", hostid) .paramEntry("search", search).build(); JsonNode response = call(getRequest); if (response.get("result").isNull() || response.get("result").get(0) == null) { return null; }/*w ww .ja v a 2 s .com*/ return response.get("result").get(0).get("itemid").asText(); }
From source file:cn.org.once.cstack.controller.ScriptingController.java
@RequestMapping(method = RequestMethod.GET) public @ResponseBody ArrayNode scriptingLoadAll() throws ServiceException, JsonProcessingException { logger.info("Load All"); User user = authentificationUtils.getAuthentificatedUser(); try {//from w ww.ja v a 2 s .com List<Script> scripts = scriptingService.loadAllScripts(); ObjectMapper mapper = new ObjectMapper(); ArrayNode array = mapper.createArrayNode(); for (Script script : scripts) { JsonNode rootNode = mapper.createObjectNode(); User user1 = userService.findById(script.getCreationUserId()); ((ObjectNode) rootNode).put("id", script.getId()); ((ObjectNode) rootNode).put("title", script.getTitle()); ((ObjectNode) rootNode).put("content", script.getContent()); ((ObjectNode) rootNode).put("creation_date", script.getCreationDate().toString()); ((ObjectNode) rootNode).put("creation_user", user1.getFirstName() + " " + user1.getLastName()); array.add(rootNode); } return array; } finally { authentificationUtils.allowUser(user); } }
From source file:org.commonjava.indy.metrics.zabbix.api.IndyZabbixApi.java
/** * * @param host/* w ww . ja va2 s. c o m*/ * @param groupId * @param ip * @return hostid */ public String hostCreate(String host, String groupId, String ip) throws IOException { // host not exists, create it. ObjectMapper mapper = new ObjectMapper(); ArrayNode groups = mapper.createArrayNode(); ObjectNode group = mapper.createObjectNode(); group.put("groupid", groupId); groups.add(group); // "interfaces": [ // { // "type": 1, // "main": 1, // "useip": 1, // "ip": "192.168.3.1", // "dns": "", // "port": "10050" // } // ], ObjectNode interface1 = mapper.createObjectNode(); // JSONObject interface1 = new JSONObject(); interface1.put("type", 1); interface1.put("main", 1); interface1.put("useip", 1); interface1.put("ip", ip); interface1.put("dns", ""); interface1.put("port", "10050"); Request request = RequestBuilder.newBuilder().method("host.create").paramEntry("host", host) .paramEntry("groups", groups).paramEntry("interfaces", new Object[] { interface1 }).build(); JsonNode response = call(request); return response.get("result").get("hostids").get(0).asText(); }
From source file:io.macgyver.neorx.rest.NeoRxClientIntegrationTest.java
@Test public void testArray() throws JsonProcessingException, IOException { ObjectMapper m = new ObjectMapper(); ArrayNode an = m.createArrayNode(); an.add("foo"); an.add("bar"); ArrayNode an2 = m.createArrayNode(); an2.add(1);//from w w w. ja v a 2s . c om an2.add(2); JsonNode n = getClient().execCypher("create (a:JUnit) set a.array1={array1},a.array2={array2} return a", "array1", an, "array2", an2).toBlocking().first(); Assertions.assertThat(n.path("array1").get(0).asText()).isEqualTo("foo"); Assertions.assertThat(n.path("array1").get(1).asText()).isEqualTo("bar"); Assertions.assertThat(n.path("array2").get(0).asInt()).isEqualTo(1); Assertions.assertThat(n.path("array2").get(1).asInt()).isEqualTo(2); }
From source file:scott.barleyrs.rest.QueryResultMessageBodyWriter.java
@Override public void writeTo(QueryResult<?> result, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { System.out.println("converting QueryResult to JSON"); result.getEntityContext().setEntityContextState(EntityContextState.INTERNAL); try {/*from ww w .j ava 2 s. co m*/ ObjectMapper mapper = new ObjectMapper(); JsonGenerator gen = mapper.getFactory().createGenerator(entityStream); ArrayNode array = mapper.createArrayNode(); for (Entity entity : result.getEntityList()) { Set<Entity> started = new HashSet<>(); array.add(toJson(mapper, entity, started)); } gen.writeTree(array); } finally { result.getEntityContext().setEntityContextState(EntityContextState.USER); } }
From source file:org.commonjava.indy.metrics.zabbix.api.IndyZabbixApi.java
/** * * @param name/* ww w. j a v a 2 s . c o m*/ * @return hostid */ public String getHost(String name) throws IOException { ObjectMapper mapper = new ObjectMapper(); ObjectNode jsonNode = mapper.createObjectNode(); ArrayNode arrayNode = mapper.createArrayNode(); arrayNode.add(name); jsonNode.put("host", arrayNode); Request request = RequestBuilder.newBuilder().method("host.get").paramEntry("filter", jsonNode).build(); JsonNode response = call(request); if (response.get("result").isNull() || response.get("result").get(0) == null) { return null; } return response.get("result").get(0).get("hostid").asText(); }
From source file:org.commonjava.indy.metrics.zabbix.api.IndyZabbixApi.java
/** * * @param name// ww w . j ava2 s . c o m * @return groupId */ public String getHostgroup(String name) throws IOException { ObjectMapper mapper = new ObjectMapper(); ObjectNode jsonNode = mapper.createObjectNode(); ArrayNode arrayNode = mapper.createArrayNode(); arrayNode.add(name); jsonNode.put("name", arrayNode); Request request = RequestBuilder.newBuilder().method("hostgroup.get").paramEntry("filter", jsonNode) .build(); JsonNode response = call(request); if (response.get("result").isNull() || response.get("result").get(0) == null) { return null; } return response.get("result").get(0).get("groupid").asText(); }
From source file:org.onosproject.tvue.TopologyResource.java
/** * Returns a JSON array of all paths between the specified hosts. * * @param src source host id//from w w w . j a v a 2s .c o m * @param dst target host id * @return JSON array of paths */ @javax.ws.rs.Path("/paths/{src}/{dst}") @GET @Produces("application/json") public Response paths(@PathParam("src") String src, @PathParam("dst") String dst) { ObjectMapper mapper = new ObjectMapper(); PathService pathService = get(PathService.class); Set<Path> paths = pathService.getPaths(elementId(src), elementId(dst)); ArrayNode pathsNode = mapper.createArrayNode(); for (Path path : paths) { pathsNode.add(json(mapper, path)); } // Now put the vertexes and edges into a root node and ship them off ObjectNode rootNode = mapper.createObjectNode(); rootNode.set("paths", pathsNode); return Response.ok(rootNode.toString()).build(); }