List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.fizzed.stork.launcher.JacksonUtil.java
public static JsonNode merge(JsonNode mainNode, JsonNode updateNode) { Iterator<String> fieldNames = updateNode.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode jsonNode = mainNode.get(fieldName); // if field exists and is an embedded object if (jsonNode != null && jsonNode.isObject()) { merge(jsonNode, updateNode.get(fieldName)); } else {// w w w . j a v a 2s . com if (mainNode instanceof ObjectNode) { // Overwrite field JsonNode value = updateNode.get(fieldName); ((ObjectNode) mainNode).put(fieldName, value); } } } return mainNode; }
From source file:de.dfki.kiara.jsonrpc.JsonRpcProtocol.java
public static Object parseMessageId(JsonNode messageNode) throws MessageDeserializationException { JsonNode idNode = messageNode.get("id"); Object id = null;//from www.j a va 2 s . com if (idNode != null) { if (!idNode.isTextual() && !idNode.isNumber() && !idNode.isNull()) { throw new MessageDeserializationException("Invalid 'id' member"); } if (idNode.isTextual()) { id = idNode.textValue(); } else if (idNode.isNumber()) { id = idNode.numberValue(); } } return id; }
From source file:org.gravidence.gravifon.db.ViewQueryResultsExtractor.java
/** * Extracts a property from a view query results row. * //ww w . ja va2 s . c om * @param propertyType property object type * @param propertyName property name * @param row a row * @return <code>propertyType</code> object */ private static <T> T extractProperty(Class<T> propertyType, String propertyName, JsonNode row) { try { return SharedInstanceHolder.OBJECT_MAPPER.treeToValue(row.get(propertyName), propertyType); } catch (JsonProcessingException ex) { throw new JsonException(ex); } }
From source file:com.galenframework.ide.devices.tasks.DeviceTaskParser.java
public static DeviceTask parseTask(ObjectMapper mapper, JsonNode jsonNode) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { DeviceTask deviceTask = new DeviceTask(); deviceTask.setName(jsonNode.get("name").asText()); deviceTask.setCommands(parseCommands(mapper, jsonNode.get("commands"))); return deviceTask; }
From source file:controllers.Maps.java
/** * Resolves the longitude and latitude for a given address ID * * @param addressId The address to resolve * @return A promise with the longitude and latitude *///from w ww . j a v a 2s. com @InjectContext // TODO: inject context probably does not work here public static Promise<F.Tuple<Double, Double>> getLatLongPromise(int addressId) { AddressDAO dao = DataAccess.getInjectedContext().getAddressDAO(); Address address = dao.getAddress(addressId); if (address != null) { return WS.url(ADDRESS_RESOLVER) .setQueryParameter("street", address.getNum() + " " + address.getStreet()) .setQueryParameter("city", address.getCity()).setQueryParameter("country", "Belgium") // TODO: uncomment postalcode line, it's only commented for test data purposes // .setQueryParameter("postalcode", address.getZip()) .setQueryParameter("format", "json").get().map(response -> { JsonNode node = response.asJson(); if (node.size() > 0) { JsonNode first = node.get(0); return new F.Tuple<>(first.get("lat").asDouble(), first.get("lon").asDouble()); } else return null; }); } else throw new DataAccessException("Could not find address by ID"); }
From source file:com.buzzcoders.yasw.widgets.map.support.GMapUtils.java
/** * Returns the coordinates of the specified address. * //from w w w . jav a2 s.c om * @param addressText the address to look * @return the latitude and longitude information */ public static LatLng getAddressCoordinates(String addressText) { LatLng coordinates = null; GetMethod locateAddressGET = null; HttpClient client = null; try { String addressUrlEncoded = URLEncoder.encode(addressText, "UTF-8"); String locationFindURL = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=" + addressUrlEncoded; client = new HttpClient(); locateAddressGET = new GetMethod(locationFindURL); int httpRetCode = client.executeMethod(locateAddressGET); if (httpRetCode == HttpStatus.SC_OK) { String responseBodyAsString = locateAddressGET.getResponseBodyAsString(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); JsonNode jsonRoot = mapper.readTree(responseBodyAsString); JsonNode location = jsonRoot.path("results").get(0).path("geometry").path("location"); JsonNode lat = location.get("lat"); JsonNode lng = location.get("lng"); coordinates = new LatLng(lat.asDouble(), lng.asDouble()); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (locateAddressGET != null) locateAddressGET.releaseConnection(); if (client != null) client.getState().clear(); } return coordinates; }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java
private static int getTimeBetweenStations(String line, String startStation, String endStation, Context context) {/*from w ww. j a v a 2 s. c o m*/ int ret = 1; try { String bufferString = Util.stringFromJsonAssets(context, "stations/metro_stations.json"); JsonNode actualObj = Util.stringToJsonNode(bufferString); JsonNode stationsNode = line.contains("M1") ? actualObj.get("M1") : actualObj.get("M2"); int i1 = 0, i2 = 1; for (int i = 0; i < stationsNode.size(); i++) { if (stationsNode.get(i).get("name").asText().equals(startStation)) i1 = i; else if (stationsNode.get(i).get("name").asText().equals(endStation)) i2 = i; } ret = Math.abs(i2 - i1); } catch (Exception e) { LOG.e(e.getLocalizedMessage()); } return ret; }
From source file:com.baasbox.commands.ScriptsResource.java
private static JsonNode wsCall(JsonNode command, JsonCallback callback) throws CommandException { try {//from w w w. j ava 2 s. c o m return ScriptingService.callJsonSync(command.get(ScriptCommand.PARAMS)); } catch (Exception e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } }
From source file:net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils.java
/** * Returns the port name for the column label. * * @param columnLabel/*from www . j a va2 s . c o m*/ * the column label * @param columnNameMapping * @return the port name for the column label */ public static String getPortName(String columnLabel, JsonNode jsonNode) { String portName = columnLabel; if (jsonNode != null && jsonNode.has("columnNames")) { for (JsonNode mappingNode : jsonNode.get("columnNames")) { if (columnLabel.equals(mappingNode.get("column").textValue())) { portName = mappingNode.get("port").textValue(); break; } } } return portName; }
From source file:net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils.java
/** * @param jsonNode//w w w . ja v a2 s .c om * @return */ public static Range getRange(JsonNode jsonNode) { Range range = new Range(); if (jsonNode != null) { if (jsonNode.has("start")) { range.setStart(jsonNode.get("start").intValue()); } if (jsonNode.has("end")) { range.setEnd(jsonNode.get("end").intValue()); } if (jsonNode.has("excludes")) { List<Range> excludes = new ArrayList<>(); for (JsonNode rangeNode : jsonNode.get("excludes")) { excludes.add(getRange(rangeNode)); } range.setExcludes(excludes); } } return range; }