List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:com.basistech.yca.JsonNodeFlattener.java
private static void traverseArray(JsonNode node, String pathSoFar, Dictionary<String, Object> map) throws IOException { for (int nodeIndex = 0; nodeIndex < node.size(); nodeIndex++) { String path = pathSoFar + "[" + nodeIndex + "]"; traverse(node.get(nodeIndex), path, map); }//w w w . j av a 2 s. c o m }
From source file:com.nirmata.workflow.details.JsonSerializer.java
public static RunnableTaskDag getRunnableTaskDag(JsonNode node) { List<TaskId> children = Lists.newArrayList(); JsonNode childrenNode = node.get("dependencies"); if ((childrenNode != null) && (childrenNode.size() > 0)) { childrenNode.forEach(n -> children.add(new TaskId(n.asText()))); }//www. j a v a 2s . c o m return new RunnableTaskDag(new TaskId(node.get("taskId").asText()), children); }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.STrainData.java
public static boolean hasLine(String line, Context context) { String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename); JsonNode actualObj = Util.stringToJsonNode(bufferString); JsonNode lines = actualObj.get("timetable"); String[] sublines = line.split(","); for (int i = 0; i < lines.size(); i++) { JsonNode lineJson = lines.get(i); for (int j = 0; j < sublines.length; j++) { if (lineJson.get("line").asText().equalsIgnoreCase(sublines[j].trim())) { return true; }//from w w w . ja v a 2s. c o m } } return false; }
From source file:org.fcrepo.importexport.common.BagProfile.java
private static Set<String> arrayValues(final JsonNode json, final String key) { final JsonNode values = json.get(key); if (values == null) { return null; }/*from w ww . j a v a 2s . c om*/ final Set<String> results = new HashSet<>(); for (int i = 0; i < values.size(); i++) { results.add(values.get(i).asText()); } return results; }
From source file:com.spoiledmilk.ibikecph.search.HTTPAutocompleteHandler.java
public static JsonNode getOiorestGeocode(String urlString, String houseNumber) { JsonNode rootNode = performGET(urlString); JsonNode ret = null;/*from w w w.j a v a 2 s.c om*/ if (rootNode != null && rootNode.size() != 0) { ret = rootNode.get(0); for (int i = 0; i < rootNode.size(); i++) { if (rootNode.get(i).has("husnr") && rootNode.get(i).get("husnr").asText().toLowerCase(Locale.US).equals(houseNumber)) { ret = rootNode.get(i); break; } } } if (ret != null && ret.has("husnr")) { LOG.d("Geocode succesfull, searched number = " + houseNumber + " foundNumber = " + ret.get("husnr").asText()); } return ret; }
From source file:com.twosigma.beakerx.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").toString(), 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)); }// ww w . j a va 2 s.co m values.add(val); } } } } return values; }
From source file:com.spoiledmilk.ibikecph.search.HTTPAutocompleteHandler.java
public static List<JsonNode> getKortforsyningenAutocomplete(Location currentLocation, Address address) { String urlString;/*from w w w . j a v a 2s. c o m*/ List<JsonNode> list = new ArrayList<JsonNode>(); try { urlString = "http://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method="; if ((address.number == null || address.number.equals("")) && (address.zip == null || address.zip.equals("")) && (address.city == null || address.city.equals("") || address.city.equals(address.street))) { urlString += "vej"; // street search } else { urlString += "adresse"; // address search } urlString += "&vejnavn=*" + URLEncoder.encode(address.street, "UTF-8") + "*"; if (!(address.number == null || address.number.equals(""))) { urlString += "&husnr=" + address.number; } 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.zip != null & !address.zip.equals("")) { urlString = urlString + "&postnr=" + address.zip; } if (address.city != null & !address.city.equals("") && !address.city.equals(address.street)) { // urlString = urlString + "&by=" + URLEncoder.encode(address.city.trim(), "UTF-8") + "*"; urlString = urlString + "&postdist=*" + URLEncoder.encode(address.city.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 (Exception e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return list; }
From source file:models.metadata.UserGroup.java
public static List<UserGroup> all() { List<UserGroup> groups = new ArrayList<UserGroup>(); JsonNode jsonNode = APICall.callAPI(GET_ALL_GROUP_CALL); if (jsonNode == null || jsonNode.has("error") || !jsonNode.isArray()) { return groups; }/*from www.ja v a 2 s . c o m*/ for (int i = 0; i < jsonNode.size(); i++) { JsonNode json = jsonNode.path(i); UserGroup newGroup = new UserGroup(json.path("id").asLong(), json.path("author").asText(), json.path("groupName").asText(), json.path("authorId").asLong()); List<User> adminList = new ArrayList<>(); List<User> memberList = new ArrayList<>(); Gson gson = new Gson(); for (int j = 0; j < json.path("adminList").size(); j++) adminList.add(gson.fromJson(json.path("adminList").get(j).toString(), User.class)); newGroup.setAdminList(adminList); for (int j = 0; j < json.path("memberList").size(); j++) memberList.add(gson.fromJson(json.path("memberList").get(j).toString(), User.class)); newGroup.setMemberList(memberList); groups.add(newGroup); } return groups; }
From source file:com.hpcloud.util.Serialization.java
/** * Returns the {@code node} deserialized to an instance of <T> with the implementation of <T> * being selected from the registered targets for the node's root key. * /*from w w w .j a v a 2 s . c o m*/ * @throws IllegalArgumentException if {@code node} does not contain a single root key * @throws IllegalStateException if no target type has been registered for the {@code node}'s root * key * @throws RuntimeException if deserialization fails */ public static <T> T fromJson(JsonNode node) { Preconditions.checkArgument(node.size() == 1, "The node must contain a single root key: %s", node); String rootKey = node.fieldNames().next(); @SuppressWarnings("unchecked") Class<T> targetType = (Class<T>) targetTypes.get(rootKey); if (targetType == null) throw new IllegalStateException("No target type is registered for the root key " + rootKey); if (targetType.isPrimitive() || Primitives.isWrapperType(targetType)) { try { return rootMapper.reader(targetType).readValue(node); } catch (IOException e) { throw Exceptions.uncheck(e, "Failed to deserialize json: {}", node); } } else { T object = Injector.getInstance(targetType); injectMembers(object, node); return object; } }
From source file:org.primaldev.ppm.util.ChartTypeGenerator.java
public static ChartTypeComponent generateChart(byte[] reportData) { // Convert json to pojo JsonNode jsonNode = convert(reportData); // Title//from ww w . ja v a 2 s . c o m JsonNode titleNode = jsonNode.get("title"); String title = null; if (titleNode != null) { title = titleNode.textValue(); } ChartTypeComponent chartComponent = new ChartTypeComponent(title); // Retrieve data sets JsonNode datasetsNode = jsonNode.get("datasets"); // If no data was returned if (datasetsNode.size() == 0) { chartComponent.addChart(null, null, "Not enough data"); return chartComponent; } if (datasetsNode != null && datasetsNode.isArray()) { Iterator<JsonNode> dataIterator = datasetsNode.iterator(); while (dataIterator.hasNext()) { JsonNode datasetNode = dataIterator.next(); JsonNode descriptionNode = datasetNode.get("description"); String description = null; if (descriptionNode != null) { description = descriptionNode.textValue(); } JsonNode dataNode = datasetNode.get("data"); if (dataNode == null || dataNode.size() == 0) { chartComponent.addChart(description, null, "Not enough data"); } else { String[] names = new String[dataNode.size()]; Number[] values = new Number[dataNode.size()]; int index = 0; Iterator<String> fieldIterator = dataNode.fieldNames(); while (fieldIterator.hasNext()) { String field = fieldIterator.next(); names[index] = field; values[index] = dataNode.get(field).numberValue(); index++; } // Generate chart (or 'no data' message) if (names.length > 0) { Component chart = createChart(datasetNode, names, values); chartComponent.addChart(description, chart, null); } else { chartComponent.addChart(description, null, "Not enough data"); } } } } return chartComponent; }