List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:com.github.fge.jsonpatch.diff.JsonDiff.java
private static void computeArray(final Map<JsonPointer, JsonNode> ret, final JsonPointer pointer, final JsonNode source, final JsonNode target) { final int size = Math.min(source.size(), target.size()); for (int i = 0; i < size; i++) computeUnchanged(ret, pointer.append(i), source.get(i), target.get(i)); }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java
private static int getTimeBetweenStations(String line, String startStation, String endStation, Context context) {/*from ww w. j a v a 2s . c om*/ 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:org.openmhealth.shim.jawbone.mapper.JawboneDataPointMapper.java
/** * @param listEntryNode an individual entry node from the "items" array of a Jawbone endpoint response * @param unixEpochTimestamp unix epoch seconds timestamp from a time property in the list entry node * @return the appropriate {@link ZoneId} for the timestamp parameter based on the timezones contained within the * list entry node/* w ww . j av a 2 s .c o m*/ */ static ZoneId getTimeZoneForTimestamp(JsonNode listEntryNode, Long unixEpochTimestamp) { Optional<JsonNode> optionalTimeZonesNode = asOptionalNode(listEntryNode, "details.tzs"); Optional<JsonNode> optionalTimeZoneNode = asOptionalNode(listEntryNode, "details.tz"); ZoneId zoneIdForTimestamp = ZoneOffset.UTC; // set default to Z in case problems with getting timezone if (optionalTimeZonesNode.isPresent() && optionalTimeZonesNode.get().size() > 0) { JsonNode timeZonesNode = optionalTimeZonesNode.get(); if (timeZonesNode.size() == 1) { zoneIdForTimestamp = parseZone(timeZonesNode.get(0).get(TIMEZONE_ENUM_INDEX_TZ)); } else { long currentLatestTimeZoneStart = 0; for (JsonNode timeZoneNodesEntry : timeZonesNode) { long timeZoneStartTime = timeZoneNodesEntry.get(TIMEZONE_ENUM_INDEX_START).asLong(); if (unixEpochTimestamp >= timeZoneStartTime) { if (timeZoneStartTime > currentLatestTimeZoneStart) { // we cannot guarantee the order of the // "tzs" array and we need to find the latest timezone that started before our time zoneIdForTimestamp = parseZone(timeZoneNodesEntry.get(TIMEZONE_ENUM_INDEX_TZ)); currentLatestTimeZoneStart = timeZoneStartTime; } } } } } else if (optionalTimeZoneNode.isPresent() && !optionalTimeZoneNode.get().isNull()) { zoneIdForTimestamp = parseZone(optionalTimeZoneNode.get()); } return zoneIdForTimestamp; }
From source file:com.ning.metrics.action.hdfs.data.parser.SmileRowSerializer.java
public static void eventToRow(Registrar r, SmileEnvelopeEventDeserializer deserializer, Rows rows) { final SmileEnvelopeEvent event; try {//from w w w .ja v a2s . c o m event = deserializer.getNextEvent(); } catch (IOException e) { throw new RowAccessException(e); } final JsonNode node = (JsonNode) event.getData(); final Map<Short, GoodwillSchemaField> schema = r.getSchema(event.getName()); final List<ColumnKey> columnKeyList = new ArrayList<ColumnKey>(node.size()); final List<JsonNodeComparable> data = new ArrayList<JsonNodeComparable>(node.size()); // Without Goodwill integration, simply pass the raw json if (schema == null) { final Iterator<String> nodeFieldNames = node.fieldNames(); while (nodeFieldNames.hasNext()) { columnKeyList.add(new DynamicColumnKey(nodeFieldNames.next())); } final Iterator<JsonNode> nodeElements = node.elements(); while (nodeElements.hasNext()) { JsonNode next = nodeElements.next(); if (next == null) { next = NullNode.getInstance(); } data.add(new JsonNodeComparable(next)); } } else { // With Goodwill, select only the fields present in the Goodwill schema, and preserve ordering for (final GoodwillSchemaField schemaField : schema.values()) { final String schemaFieldName = schemaField.getName(); columnKeyList.add(new DynamicColumnKey(schemaFieldName)); JsonNode delegate = node.get(schemaFieldName); if (delegate == null) { delegate = NullNode.getInstance(); } data.add(new JsonNodeComparable(delegate)); } } rows.add(RowFactory.getRow(new RowSchema(event.getName(), columnKeyList), data)); }
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(); }/*from w w w . j a v a2s .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.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java
@SuppressWarnings("unchecked") public static List<List<?>> getValues(BeakerObjectConverter parent, JsonNode n, ObjectMapper mapper) throws IOException { List<List<?>> values = null; List<String> classes = null; if (n.has("types")) classes = mapper.readValue(n.get("types").asText(), List.class); if (n.has("values")) { JsonNode nn = n.get("values"); values = new ArrayList<List<?>>(); if (nn.isArray()) { for (JsonNode nno : nn) { if (nno.isArray()) { ArrayList<Object> val = new ArrayList<Object>(); for (int i = 0; i < nno.size(); i++) { JsonNode nnoo = nno.get(i); Object obj = parent.deserialize(nnoo, mapper); val.add(TableDisplayDeSerializer.getValueForDeserializer(obj, classes != null && classes.size() > i ? classes.get(i) : null)); }//from ww w .jav a 2s . c om values.add(val); } } } } return values; }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.LocalTrainData.java
public static boolean hasLine(String line, Context context) { String lineNumber = line.split(" ")[0]; String jsonStr = Util.stringFromJsonAssets(context, "stations/local-trains-timetable.json"); JsonNode root = Util.stringToJsonNode(jsonStr); JsonNode lines = root.get("local-trains"); for (int i = 0; i < lines.size(); i++) { if (lines.get(i).get("line").asText().trim().equalsIgnoreCase(lineNumber.trim())) return true; }/*from www .j a v a 2s . co m*/ return false; }
From source file:models.service.reminder.RemindService.java
/** * ?Map???,??,/* ww w .j a va2 s. co m*/ * * @param user ? * @param items ?items * * @return ??Map */ public static Map<Item, List<Option>> getCfgMapWithDefault(User user, Item[] items) { JsonNode itemsNode = getCfgJsonWithDefault(user, items); if (null == itemsNode || itemsNode.size() <= 0) { return new HashMap<>(0); } Map<Item, List<Option>> cfgMap = new HashMap<>(); Iterator<Entry<String, JsonNode>> itemsNodeFields = itemsNode.fields(); while (itemsNodeFields.hasNext()) { Entry<String, JsonNode> itemsNodeField = itemsNodeFields.next(); Iterator<JsonNode> optionsIt = itemsNodeField.getValue().elements(); List<Option> optionList = new ArrayList<>(); while (optionsIt.hasNext()) { optionList.add(Option.getByVal(optionsIt.next().asText())); } cfgMap.put(Item.getByVal(itemsNodeField.getKey()), optionList); } return cfgMap; }
From source file:com.redhat.lightblue.eval.FieldComparisonEvaluator.java
private static List<Object> makeList(Type t, JsonNode node) { if (node instanceof ArrayNode) { List<Object> list = new ArrayList<>(node.size()); for (Iterator<JsonNode> itr = ((ArrayNode) node).elements(); itr.hasNext();) { list.add(t.fromJson(itr.next())); }//w ww . j ava 2 s . c om return list; } return null; }
From source file:com.spoiledmilk.ibikecph.search.HTTPAutocompleteHandler.java
public static List<JsonNode> getKortforsyningenPlaces(Location currentLocation, Address address) { String urlString;/*from ww w . j a v a2 s . c om*/ List<JsonNode> list = new ArrayList<JsonNode>(); if (address.city == null || address.city.equals("")) { address.city = address.street; } try { urlString = "http://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method=sted&stednavn=" + "*" + URLEncoder.encode(address.street, "UTF-8") + "*&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"; if (address.city != null & !address.city.equals("") && !address.street.equals(address.street)) { // urlString = urlString + "&by=" + URLEncoder.encode(address.city.trim(), "UTF-8") + "*"; // urlString += "&postdist=" + URLEncoder.encode(address.city.trim(), "UTF-8");// + "*"; } 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("navn")) list.add(features.get(i)); } } } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return list; }