List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.pros.jsontransform.plugin.expression.FunctionAvgChildrenAge.java
public static JsonNode evaluate(final JsonNode argsNode, final JsonNode resultNode, final ObjectTransformer transformer) throws ObjectTransformerException { double avg = 0.0; // argument $value indicates children array in source node context if (argsNode.get("$value") != null) { // transformer resolves $value to corresponding node JsonNode childrenArray = transformer.transformValueNode(transformer.getSourceNode(), argsNode); if (childrenArray.isArray()) { for (JsonNode child : childrenArray) { avg += child.path("age").asDouble(); }// ww w. j av a2 s. c o m avg = avg / childrenArray.size(); } } // use argsNode to hold temporary return value node ObjectNode holderNode = (ObjectNode) argsNode; holderNode.put("returnValue", avg); return holderNode.get("returnValue"); }
From source file:com.redhat.lightblue.query.RValueExpression.java
/** * Parses an rvalue from a json node.//www .j av a2 s . co m */ public static RValueExpression fromJson(JsonNode node) { if (node instanceof ObjectNode) { if (node.size() == 1) { JsonNode path = node.get("$valueof"); if (path != null && path.isValueNode()) { return new RValueExpression(new Path(path.asText())); } } else { return new RValueExpression(); } } else if (node.isValueNode()) { if (node.asText().equals("$null")) { return new RValueExpression(RValueType._null); } else { return new RValueExpression(Value.fromJson(node)); } } throw Error.get(QueryConstants.ERR_INVALID_RVALUE_EXPRESSION, node.toString()); }
From source file:com.reprezen.swagedit.json.references.JsonReference.java
/** * Returns true if the argument can be identified as a JSON reference node. * /*ww w . j a va 2 s . com*/ * A node is considered a reference if it is an object node and has a field named $ref having a textual value. * * @param node * @return true if a reference node */ public static boolean isReference(JsonNode value) { return value != null && value.isObject() && value.has(PROPERTY) && value.get(PROPERTY).isTextual(); }
From source file:dk.kk.ibikecphlib.search.HTTPAutocompleteHandler.java
public static List<JsonNode> getKortforsyningenPlaces(Location currentLocation, Address address) { String urlString;// w w w. j a v a2s. c o m List<JsonNode> list = new ArrayList<JsonNode>(); if (!address.hasCity()) { // TODO: Seriously address.setCity(address.getStreet()); } try { // TODO: Removed a wildcard String stednavn = URLEncoder.encode(address.getStreet(), "UTF-8") + "*"; urlString = "https://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method=stedv2&stednavn=" + stednavn + "&geop=" + "" + Util.limitDecimalPlaces(currentLocation.getLongitude(), 6) + "," + "" + Util.limitDecimalPlaces(currentLocation.getLatitude(), 6) + "&georef=EPSG:4326&outgeoref=EPSG:4326&login=ibikecph&password=Spoiledmilk123&hits=10"; // &distinct=true gave an error from the API // DB_SQL_PROBLEM. Error executing SQL: ERROR: syntax error at or near "stednavn" Position: 453 JsonNode rootNode = performGET(urlString); if (rootNode.has("features")) { JsonNode features = rootNode.get("features"); for (JsonNode featureNode : features) { if (featureNode.has("properties") && featureNode.get("properties").has("stednavneliste") && featureNode.get("properties").size() > 0) list.add(featureNode); } } } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return list; }
From source file:com.leclercb.taskunifier.gui.processes.license.ProcessGetTrial.java
public static String getLicense(HttpResponse response) { if (!response.isSuccessfull()) return null; try {/* w w w. ja va2s. c o m*/ ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readTree(response.getContent()); String code = node.get("code").asText(); String license = null; if (EqualsUtils.equals(code, "0")) { license = node.get("data").get("license").asText(); } return license; } catch (Exception e) { GuiLogger.getLogger().log(Level.WARNING, "Cannot read license", e); return null; } }
From source file:com.pros.jsontransform.constraint.ConstraintRange.java
public static void validate(final JsonNode constraintNode, final JsonNode resultNode, final ObjectTransformer transformer) throws ObjectTransformerException { boolean ltRangeValid = true; boolean gtRangeValid = true; JsonNode rangeNode = constraintNode.get(Constraint.$RANGE.toString()); if (rangeNode.isObject()) { JsonNode ltNode = rangeNode.path("less-than"); if (!ltNode.isMissingNode()) { if (resultNode.isNumber() && ltNode.isNumber()) { ltRangeValid = resultNode.asDouble() < ltNode.asDouble(); } else if (resultNode.isTextual() && ltNode.isTextual()) { ltRangeValid = resultNode.asText().compareTo(ltNode.asText()) < 0; }/* w w w. jav a 2 s . c o m*/ } JsonNode gtNode = rangeNode.path("greater-than"); if (!gtNode.isMissingNode()) { if (resultNode.isNumber() && gtNode.isNumber()) { gtRangeValid = resultNode.asDouble() > gtNode.asDouble(); } else if (resultNode.isTextual() && gtNode.isTextual()) { gtRangeValid = resultNode.asText().compareTo(gtNode.asText()) > 0; } } } if (ltRangeValid == false || gtRangeValid == false) { throw new ObjectTransformerException("Constraint violation [" + Constraint.$RANGE.toString() + "]" + " on transform node " + transformer.getTransformNodeFieldName()); } }
From source file:com.baasbox.commands.ScriptsResource.java
private static JsonNode storageCommand(JsonNode command, JsonCallback callback) throws CommandException { JsonNode moduleId = command.get(ScriptCommand.ID); if (moduleId == null || !moduleId.isTextual()) { throw new CommandParsingException(command, "error parsing module id"); }//from w w w .ja v a 2 s.c o m String id = moduleId.asText(); JsonNode params = command.get(ScriptCommand.PARAMS); if (params == null || !params.isObject()) { throw new CommandParsingException(command, "error parsing params"); } JsonNode actionNode = params.get("action"); if (actionNode == null || !actionNode.isTextual()) { throw new CommandParsingException(command, "error parsing action"); } String action = actionNode.asText(); ODocument result; if ("get".equals(action)) { try { result = ScriptingService.getStore(id); } catch (ScriptException e) { //should never happen throw new CommandExecutionException(command, "script does not exists"); } } else if ("set".equals(action)) { JsonNode args = params.get("args"); if (args == null) { args = NullNode.getInstance(); } if (!args.isObject() && !args.isNull()) { throw new CommandExecutionException(command, "Stored values should be objects or null"); } try { result = ScriptingService.resetStore(id, args); } catch (ScriptException e) { throw new CommandExecutionException(command, "script does not exists"); } } else if ("swap".equals(action)) { if (callback == null) throw new CommandExecutionException(command, "missing function callback"); try { result = ScriptingService.swap(id, callback); } catch (ScriptException e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } } else if ("trade".equals(action)) { if (callback == null) throw new CommandExecutionException(command, "missing function callback"); try { result = ScriptingService.trade(id, callback); } catch (ScriptException e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } } else { throw new CommandParsingException(command, "unknown action: " + action); } if (result == null) { return NullNode.getInstance(); } else { String s = result.toJSON(); try { ObjectNode jsonNode = (ObjectNode) Json.mapper().readTree(s); jsonNode.remove("@version"); jsonNode.remove("@type"); return jsonNode; } catch (IOException e) { throw new CommandExecutionException(command, "error converting result", e); } } }
From source file:com.amazonaws.services.iot.client.shadow.AwsIotJsonDeserializer.java
public static long deserializeVersion(AbstractAwsIotDevice device, String jsonState) throws IOException { ObjectMapper jsonObjectMapper = device.getJsonObjectMapper(); JsonNode node = jsonObjectMapper.readTree(jsonState); if (node == null) { throw new IOException("Invalid shadow document received for " + device.getThingName()); }/* w ww .j a va 2 s . c om*/ JsonNode versionNode = node.get("version"); if (versionNode == null) { throw new IOException("Missing version field from shadow document for " + device.getThingName()); } return versionNode.asLong(); }
From source file:com.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java
@SuppressWarnings("unchecked") public static List<String> getClasses(JsonNode n, ObjectMapper mapper) throws IOException { List<String> classes = null; if (n.has("types")) classes = mapper.readValue(n.get("types").asText(), List.class); return classes; }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java
public static ArrayList<ITransportationInfo> getNext3Arrivals(String line, String startStation, String endStation, Context context) { ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>(); String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename); JsonNode actualObj = Util.stringToJsonNode(bufferString); JsonNode lines = actualObj.get("lines"); for (int i = 0; i < lines.size(); i++) { JsonNode lineJson = lines.get(i); if (lineJson.get("name").asText().contains(line)) { Calendar calendar = Calendar.getInstance(); int day = calendar.get(Calendar.DAY_OF_WEEK); if (day == 1) day = 6;// w w w. j a va 2 s .co m else day -= 2; int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int period = 0, endTime = 0; // startTime try { if ((day == 4 || day == 5) && hour >= 0 && hour <= 7) { // Friday and Saturday night period = lineJson.get("timetable").get("friday_saturday_night").get(0).get("period") .asInt(); endTime = lineJson.get("timetable").get("friday_saturday_night").get(0).get("end_time") .asInt(); } else if ((day < 4 || day == 6) && hour >= 0 && hour <= 5) { // other days at night JsonNode timetableNode = lineJson.get("timetable"); JsonNode timetableNodeContainer = timetableNode.get("sunday_thursday_night"); period = timetableNodeContainer.get(0).get("period").asInt(); endTime = timetableNodeContainer.get(0).get("end_time").asInt(); } else { JsonNode nodeRushour = lineJson.get("timetable").get("weekdays_rushour"); JsonNode nodeOutsideRushour = lineJson.get("timetable").get("weekdays_outside_rushour"); if ((day >= 0 && day < 5) && hour >= nodeRushour.get(0).get("start_time").asInt() && hour < nodeRushour.get(0).get("end_time").asInt()) { endTime = nodeRushour.get(0).get("end_time").asInt(); period = nodeRushour.get(0).get("period").asInt(); } else if ((day >= 0 && day < 5) && hour >= nodeRushour.get(1).get("start_time").asInt() && hour < nodeRushour.get(1).get("end_time").asInt()) { endTime = nodeRushour.get(1).get("end_time").asInt(); period = nodeRushour.get(1).get("period").asInt(); } else if (hour >= nodeOutsideRushour.get(0).get("start_time").asInt() && hour < nodeOutsideRushour.get(0).get("end_time").asInt()) { endTime = nodeOutsideRushour.get(0).get("end_time").asInt(); period = nodeOutsideRushour.get(0).get("period").asInt(); } else { endTime = nodeOutsideRushour.get(1).get("end_time").asInt(); period = nodeOutsideRushour.get(1).get("period").asInt(); } } int currentHour = hour; int currentMinute = minute; int count = 0; period *= getTimeBetweenStations(line, startStation, endStation, context); while (count < 3) { for (int k = 0; k < 60 && count < 3; k += period % 60) { if (k >= currentMinute) { currentMinute = k % 60; currentHour += period / 60; String arrivalTime = (currentHour < 10 ? "0" + currentHour : "" + currentHour) + ":" + (currentMinute < 10 ? "0" + currentMinute : "" + currentMinute); int destHour = currentHour + period / 60; int destMinute = currentMinute + period % 60; if (destMinute > 59) { destHour += destMinute / 60; destMinute = destMinute % 60; } String destTime = (destHour < 10 ? "0" + destHour : "" + destHour) + ":" + (destMinute < 10 ? "0" + destMinute : "" + destMinute); ret.add(new MetroData(arrivalTime, destTime, period)); count++; } } currentMinute = 0; if ((++currentHour) >= endTime) break; } } catch (Exception e) { LOG.e(e.getLocalizedMessage()); } break; } } return ret; }