List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.xively.client.http.util.ParserUtil.java
public static <T extends DomainObject> Collection<T> toConnectedObjects(String body, Class elementType) { log.debug(String.format("Parsing string to objects: %s", body)); Collection<T> objs;/*from w w w. j ava 2 s. c om*/ CollectionType collectionType = TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, elementType); try { JsonNode node = getObjectMapper().reader().readTree(body); JsonNode total = node.get("totalResults"); if (total != null) { JsonNode results = node.get("results"); objs = getObjectMapper().readValue(results.toString(), collectionType); log.debug(String.format("Parsed string to %s objects", total)); } else { objs = getObjectMapper().readValue(body, collectionType); } } catch (IOException e) { throw new ParseToObjectException(String.format("Unable to parse [%s] to %s.", body, elementType), e); } return objs; }
From source file:de.qaware.cloud.deployer.commons.config.util.ContentTreeUtil.java
/** * Reads the string with the specified key in the object tree. * * @param contentObjectTree The object tree which contains the string identified by the specified key. * @param key The key which identifies the string. * @return The value of the key in form of a string. * @throws ResourceConfigException If the key isn't available in the object tree. *///from ww w . j a v a2 s.c om public static String readStringValue(JsonNode contentObjectTree, String key) throws ResourceConfigException { if (contentObjectTree.hasNonNull(key)) { JsonNode jsonNode = contentObjectTree.get(key); if (jsonNode.isTextual()) { return jsonNode.textValue(); } else { throw new ResourceConfigException( COMMONS_MESSAGE_BUNDLE.getMessage("DEPLOYER_COMMONS_ERROR_READING_STRING_VALUE", key)); } } else { throw new ResourceConfigException( COMMONS_MESSAGE_BUNDLE.getMessage("DEPLOYER_COMMONS_ERROR_READING_NODE_VALUE", key)); } }
From source file:controllers.WebSocketsStore.java
public static WebSocket<String> handlesWs() { return new WebSocket<String>() { // Called when the Websocket Handshake is done. public void onReady(In<String> in, final Out<String> out) { connections.add(out);// ww w .j ava 2s .com // For each event received on the socket, in.onMessage(new F.Callback<String>() { public void invoke(String event) { System.out.println("This is the message: " + event); JsonNode m = ParseHandling.getMessage(event); String message = m.get("message").asText(); String origin = m.get("origin").asText(); String destination = m.get("destination").asText(); //destination = ParseHandling.calculateDestination(destination); String _destinationFinal = ParseHandling.calculateDestination(destination); if (message.equals("requestChannel")) { if (!origin.contains(":")) connectionsMap.put(origin, out); if (destination.equals("BRIDGE")) { /* in the future something should be done, not now */ } else { System.out.println("Request a Channel "); System.out.println("Origin: " + origin); System.out.println("Destination: " + destination); ConnectionStore cs = new ConnectionStore(destination, origin, message, null); cs.name = origin; cs.origin = origin; cs.destination = destination; cs.messageType = message; cs.save(); //System.out.println(connectionsMap); if (connectionsMap.get(_destinationFinal) != null) connectionsMap.get(_destinationFinal).write(event); else System.out.println("..."); /* Query<ConnectionStore> res =ConnectionStore.find.fetch("byDestination", destination); System.out.println("Size of Connection Store + " + res.findRowCount()); if (res.findRowCount()==0) { } */ } } else if (message.equals("dataAvailable")) { connectionsMap.get(_destinationFinal).write(event); } else if (message.equals("dataReceived")) { connectionsMap.get(_destinationFinal).write(event); } else if (message.equals("closeSocket")) { connectionsMap.get(_destinationFinal).write(event); } else { System.err.println("I don't know how to handle that"); connectionsMap.get(_destinationFinal).write(event); } /* if (out!=null) { Cache.set("staff", new String("test"), 30); out.write("Hello!"); } else System.out.println("out is null"); */ } }); // When the socket is closed. in.onClose(new F.Callback0() { public void invoke() { System.out.println("Disconnected"); } }); // Send a single 'Hello!' message /* for ( WebSocket.Out ss : connections) { //ss.write("Just to be sure, that everything is alive!"); }*/ } }; }
From source file:org.jboss.aerogear.sync.server.gcm.GcmDiffSyncHandler.java
private static String clientIdFromJson(JsonNode syncMessage) { final JsonNode clientId = syncMessage.get("clientId"); String content = null;//from w w w . j a v a2 s . c om if (clientId != null && !clientId.isNull()) { content = clientId.asText(); } return content; }
From source file:com.liferay.sync.engine.util.SyncSystemTestUtil.java
public static long getGuestGroupId(long syncAccountId) throws Exception { if (_guestGroupId > 0) { return _guestGroupId; }// ww w . j a va 2 s . co m Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("companyId", getCompanyId(syncAccountId)); parameters.put("name", "Guest"); Session session = SessionManager.getSession(syncAccountId); HttpResponse httpResponse = session.executePost("/group/get-group", parameters); HttpEntity httpEntity = httpResponse.getEntity(); String response = EntityUtils.toString(httpEntity); ObjectMapper mapper = new ObjectMapper(); JsonNode rootJsonNode = mapper.readTree(response); JsonNode groupIdJsonNode = rootJsonNode.get("groupId"); _guestGroupId = groupIdJsonNode.asLong(); return _guestGroupId; }
From source file:com.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java
@SuppressWarnings("unchecked") public static List<String> getColumns(JsonNode n, ObjectMapper mapper) throws IOException { List<String> columns = null; if (n.has("columnNames")) columns = mapper.readValue(n.get("columnNames").asText(), List.class); return columns; }
From source file:com.liferay.sync.engine.util.SyncSystemTestUtil.java
protected static long getCompanyId(long syncAccountId) throws Exception { if (_companyId > 0) { return _companyId; }// ww w. j av a 2 s . c om Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("virtualHost", "localhost"); Session session = SessionManager.getSession(syncAccountId); HttpResponse httpResponse = session.executePost("/company/get-company-by-virtual-host", parameters); HttpEntity httpEntity = httpResponse.getEntity(); String response = EntityUtils.toString(httpEntity); ObjectMapper mapper = new ObjectMapper(); JsonNode rootJsonNode = mapper.readTree(response); JsonNode companyIdJsonNode = rootJsonNode.get("companyId"); _companyId = companyIdJsonNode.asLong(); return _companyId; }
From source file:dk.kk.ibikecphlib.search.HTTPAutocompleteHandler.java
public static List<JsonNode> getKortforsyningenAutocomplete(Location currentLocation, Address address) { String urlString;/*from www.j a va 2s . com*/ List<JsonNode> list = new ArrayList<JsonNode>(); try { // TODO: Get this from Config urlString = "https://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method="; if ((address.hasHouseNumber()) && (address.hasZip()) && (address.getCity() == null || address.getCity().equals("") || address.getCity().equals(address.getStreet()))) { urlString += "vej"; // street search } else { urlString += "adresse"; // address search } // TODO: Removed a wildcard in the beginning of the search query. urlString += "&vejnavn=" + URLEncoder.encode(address.getStreet(), "UTF-8") + "*"; // urlString = "https://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method=adresse&vejnavn=*" // + URLEncoder.encode(address.street, "UTF-8") + "*"; if (address.hasHouseNumber()) { urlString += "&husnr=" + address.getHouseNumber() + "*"; } urlString += "&geop=" + Util.limitDecimalPlaces(currentLocation.getLongitude(), 6) + "" + "," + Util.limitDecimalPlaces(currentLocation.getLatitude(), 6) + "" + "&georef=EPSG:4326&outgeoref=EPSG:4326&login=ibikecph&password=Spoiledmilk123&hits=10"; if (address.hasZip()) { urlString = urlString + "&postnr=" + address.getZip(); } if (address.hasCity() && !address.getCity().equals(address.getStreet())) { // urlString = urlString + "&by=" + URLEncoder.encode(address.city.trim(), "UTF-8") + "*"; urlString = urlString + "&postdist=*" + URLEncoder.encode(address.getCity().trim(), "UTF-8") + "*"; } urlString += "&geometry=true"; JsonNode rootNode = performGET(urlString); if (rootNode.has("features")) { JsonNode features = rootNode.get("features"); for (int i = 0; i < features.size(); i++) { if (features.get(i).has("properties") && (features.get(i).get("properties").has("vej_navn") || features.get(i).get("properties").has("navn"))) list.add(features.get(i)); } } } catch (UnsupportedEncodingException e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return list; }
From source file:com.nirmata.workflow.details.JsonSerializer.java
public static TaskType getTaskType(JsonNode node) { return new TaskType(node.get("type").asText(), node.get("version").asText(), node.get("isIdempotent").asBoolean()); }
From source file:com.pkrete.locationservice.admin.util.LocationJSONDeserializerHelper.java
/** * Deserializes subjectMatters variable. * * @param location Location object//from w w w . j av a 2 s . com * @param node JSON node that contains the data */ public static void deserializeSubjectMatters(Location location, JsonNode node) { // Get subjectMattersService bean from Application Context SubjectMattersService service = (SubjectMattersService) ApplicationContextUtils.getApplicationContext() .getBean("subjectMattersService"); // SubjectMatters cache Map<Integer, SubjectMatter> cache = new HashMap<Integer, SubjectMatter>(); List<SubjectMatter> subjects = new ArrayList<SubjectMatter>(); // Does subject_matters node exist if (node.path("subject_matters") != null) { // Parse descriptions Iterator<JsonNode> ite = node.path("subject_matters").elements(); // Iterate redirects while (ite.hasNext()) { // Get next description JsonNode temp = ite.next(); // Parse id int id = temp.get("id") == null ? 0 : temp.get("id").intValue(); // Check if the subject is cached if (!cache.containsKey(id)) { // Get subject from DB and cache it cache.put(id, service.getSubjectMatter(id)); } if (cache.get(id) != null) { subjects.add(cache.get(id)); } } } // Set subject matters location.setSubjectMatters(subjects); }