List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.github.fge.jsonschema2avro.predicates.AvroPredicates.java
public static Predicate<AvroPayload> map() { return new Predicate<AvroPayload>() { @Override/*from www. jav a2s .co m*/ public boolean apply(final AvroPayload input) { final JsonNode node = schemaNode(input); final NodeType type = getType(node); if (NodeType.OBJECT != type) return false; final JsonNode digest = ObjectSchemaDigester.getInstance().digest(node); // FIXME: as for array digester, the result should really be // a POJO if (!digest.get("hasAdditional").booleanValue()) return false; return digest.get("properties").size() == 0 && digest.get("patternProperties").size() == 0; } }; }
From source file:com.meetingninja.csse.database.NotesDatabaseAdapter.java
public static String createNote(Note n) throws Exception { // Server URL setup String _url = getBaseUri().build().toString(); // Establish connection URL url = new URL(_url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // add request header conn.setRequestMethod(IRequest.POST); //addRequestHeader(conn, true); // prepare POST payload ByteArrayOutputStream json = new ByteArrayOutputStream(); // this type of print stream allows us to get a string easily PrintStream ps = new PrintStream(json); // Create a generator to build the JSON string JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8); // Build JSON Object jgen.writeStartObject();/*from w ww . jav a 2 s. com*/ jgen.writeStringField(Keys.Note.CREATED_BY, n.getCreatedBy()); jgen.writeStringField(Keys.Note.TITLE, n.getTitle()); jgen.writeStringField(Keys.Note.DESC, n.getDescription()); jgen.writeStringField(Keys.Note.CONTENT, n.getContent()); jgen.writeStringField(Keys.Note.UPDATED, n.getDateCreated()); jgen.writeEndObject(); jgen.close(); // Get JSON Object payload from print stream String payload = json.toString("UTF8"); Log.d("CREATENOTE_payload", payload); ps.close(); // Send payload int responseCode = sendPostPayload(conn, payload); String response = getServerResponse(conn); Log.d("CREATENOTE_response", response); String ID = ""; if (!response.isEmpty()) { JsonNode tree = MAPPER.readTree(response); if (!tree.has(Keys.Note.ID)) ID = "-1"; else ID = tree.get(Keys.Note.ID).asText(); } conn.disconnect(); return ID; }
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 w w w . j a va 2s . com*/ 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; }
From source file:nl.esciencecenter.xnatclient.data.XnatParser.java
public static int parseJsonResult(XnatObjectType type, String jsonStr, List list) throws XnatParseException { if (StringUtil.isEmpty(jsonStr)) return 0; try {//w w w .j a v a 2 s .co m JsonFactory jsonFac = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(); // use dom like parsing: JsonNode tree = mapper.readTree(jsonStr); JsonNode rootNode = null; JsonNode resultSet = tree.get("ResultSet"); if (resultSet == null) { logger.warnPrintf("Couldn't find 'ResultSet' in jsonTree\n"); // return 0; } JsonNode result = resultSet.get("Result"); if (result == null) { logger.warnPrintf("Couldn't find 'Result' in jsonTree\n"); return 0; } if (result.isArray() == false) { // logger.warnPrintf("Couldn't find 'Result' in jsonTree\n"); return 0; } rootNode = result; // parse objects: Iterator<JsonNode> els = rootNode.elements(); while (els.hasNext()) { JsonNode el = els.next(); list.add(parseXnatObject(type, el)); } } // wrap exception: catch (JsonParseException e) { throw new XnatParseException("Couldn't parse result:\n" + jsonStr + "\n---\n" + e.getMessage(), e); } catch (IOException e) { throw new XnatParseException("IOException:" + e.getMessage(), e); } return list.size(); }
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//from ww w .j a va2 s . c om */ 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.github.fge.jsonschema.TestUtils.java
public static String buildMessage(final MessageBundle BUNDLE, final String key, final JsonNode params, final JsonNode data) { final ProcessingMessage message = new ProcessingMessage().setMessage(BUNDLE.getMessage(key)); if (params != null) { String name;/*from ww w .ja v a2 s. co m*/ JsonNode value; for (final JsonNode node : params) { name = node.textValue(); value = data.get(name); message.putArgument(name, valueToArgument(value)); } } return message.getMessage(); }
From source file:com.spoiledmilk.ibikecph.search.HTTPAutocompleteHandler.java
public static List<JsonNode> getKortforsyningenPlaces(Location currentLocation, Address address) { String urlString;/*www .ja v a2 s .c o m*/ 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; }
From source file:com.spotify.docker.client.messages.AuthConfig.java
private static JsonNode extractAuthJson(final Path configPath) throws IOException { final JsonNode config = MAPPER.readTree(configPath.toFile()); if (config.has("auths")) { return config.get("auths"); }/*from w w w . jav a2s . c o m*/ return config; }
From source file:controllers.Features.java
@BodyParser.Of(BodyParser.Json.class) private static Promise<Result> removeTarget(String name, JsonNode json) { final ObjectNode feature = Json.newObject(); feature.put("name", name); feature.put("type", json.get("type").asText()); final ObjectNode target = Json.newObject(); target.put("name", json.get("target").asText()); // 1. Check if feature :HAS this target in some rule Promise<Boolean> hasValue = Feature.nodes.has(feature, target); // 2. If it doesn't, disconnect it from the target Promise<Boolean> disconnected = hasValue.flatMap(new Function<Boolean, Promise<Boolean>>() { public Promise<Boolean> apply(Boolean hasValue) { if (hasValue) { return Promise.pure(false); }// www. j av a2 s. c o m return Feature.nodes.disconnect(feature, target); } }); return disconnected.map(new Function<Boolean, Result>() { ObjectNode result = Json.newObject(); public Result apply(Boolean disconnected) { if (disconnected) { result.put("message", "Target successfully removed."); return ok(result); } result.put("message", "Target not removed."); return badRequest(result); } }); }
From source file:org.activiti.designer.eclipse.navigator.cloudrepo.sync.SyncUtil.java
public static void startImportModelBackgroundJob(final Shell shell, final String targetFileName, final IFile sourceFile) { Job uploadJob = new Job("Importing file") { protected IStatus run(IProgressMonitor monitor) { try { JsonNode modelNode = ActivitiCloudEditorUtil.importModel(sourceFile.getName(), IOUtils.toByteArray(sourceFile.getContents()), true); if (modelNode != null && modelNode.get("id") != null) { ActivitiCloudEditorUtil.downloadProcessModel(modelNode.get("id").asText(), sourceFile, false);//ww w. j a v a 2 s . co m showSuccessImportMessage(shell); } else { showErrorImportMessage(shell); } } catch (ActivitiCloudEditorSameContentException e) { showCloudEditorErrorMessage(shell, "Already in-sync", e); } catch (ActivitiCloudEditorException e) { showCloudEditorErrorMessage(shell, "Process import failed", e); } catch (Exception e) { Logger.logError(e); return Status.CANCEL_STATUS; } return Status.OK_STATUS; } }; uploadJob.setUser(true); uploadJob.schedule(); }