List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.reprezen.swaggerparser.test.ExamplesTest.java
@Parameters public static Collection<URL> findExamples() throws IOException { Collection<URL> examples = Lists.newArrayList(); Deque<URL> dirs = Queues.newArrayDeque(); String auth = System.getenv("GITHUB_AUTH") != null ? System.getenv("GITHUB_AUTH") + "@" : ""; String request = String.format("https://%sapi.github.com/repos/%s/contents/%s?ref=%s", auth, SPEC_REPO, EXAMPLES_ROOT, EXAMPLES_BRANCH); dirs.add(new URL(request)); while (!dirs.isEmpty()) { URL url = dirs.remove();//from ww w. ja va 2 s .c om String json = IOUtils.toString(url, Charsets.UTF_8); JsonNode tree = mapper.readTree(json); for (JsonNode result : iterable(tree.elements())) { String type = result.get("type").asText(); String path = result.get("path").asText(); String resultUrl = result.get("url").asText(); if (type.equals("dir")) { dirs.add(new URL(resultUrl)); } else if (type.equals("file") && (path.endsWith(".yaml") || path.endsWith(".json"))) { String downloadUrl = result.get("download_url").asText(); examples.add(new URL(downloadUrl)); } } } return examples; }
From source file:org.opendaylight.ovsdb.northbound.OvsdbRow.java
public static OvsdbRow fromJsonNode(OvsdbClient client, String dbName, JsonNode json) { JsonNode parentUuidNode = json.get(PARENTUUID); String parentUuid = null;/*from ww w . j a v a2 s .c om*/ if (parentUuidNode != null) { parentUuid = parentUuidNode.asText(); } JsonNode parentTableNode = json.get(PARENTTABLE); String parentTable = null; if (parentTableNode != null) { parentTable = parentTableNode.asText(); } JsonNode parentColumnNode = json.get(PARENTCOLUMN); String parentColumn = null; if (parentColumnNode != null) { parentColumn = parentColumnNode.asText(); } JsonNode rowNode = json.get(ROW); if (rowNode == null) { return null; } for (Iterator<String> fieldNames = rowNode.fieldNames(); fieldNames.hasNext();) { String tableName = fieldNames.next(); Row<GenericTableSchema> row = null; try { row = getRow(client, dbName, tableName, rowNode.get(tableName)); } catch (InterruptedException | ExecutionException | IOException e) { e.printStackTrace(); return null; } return new OvsdbRow(parentTable, parentUuid, parentColumn, tableName, row); } return null; }
From source file:com.flipkart.zjsonpatch.JsonPatch.java
private static JsonNode getPatchAttr(JsonNode jsonNode, String attr) { JsonNode child = jsonNode.get(attr); if (child == null) throw new InvalidJsonPatchException("Invalid JSON Patch payload (missing '" + attr + "' field)"); return child; }
From source file:org.jboss.aerogear.sync.server.netty.ConfigReader.java
private static StandaloneConfig parseProperties(final JsonNode json) { final Builder b = StandaloneConfig.host(json.get("host").asText()); b.port(json.get("port").asInt()); final JsonNode gcm = json.get("gcm"); if (gcm != null) { final JsonNode enabled = gcm.get("enabled"); if (enabled != null && enabled.asBoolean()) { b.gcmEnabled();// www . j a v a2 s. co m } final JsonNode gcmHost = gcm.get("host"); if (gcmHost != null) { b.gcmHost(gcmHost.asText()); } final JsonNode gcmPort = gcm.get("port"); if (gcmPort != null) { b.gcmPort(gcmPort.asInt()); } final JsonNode gcmSenderId = gcm.get("senderId"); if (gcmSenderId != null) { b.gcmSenderId(gcmSenderId.asLong()); } final JsonNode gcmApiKey = gcm.get("apiKey"); if (gcmApiKey != null) { b.gcmApiKey(gcmApiKey.asText()); } } return b.build(); }
From source file:com.pros.jsontransform.sort.ArraySortAscending.java
public static void sort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) throws ObjectTransformerException { // check $ascending arguments if (sortNode.get(ArraySort.$ASCENDING.name().toLowerCase()).get(ArraySort.ARGUMENT_BY) == null) { throw new ObjectTransformerException( "Missing argument " + ArraySort.ARGUMENT_BY + " in sort directive " + sortNode.toString()); }/*ww w. j ava 2 s . c o m*/ doSort(arrayNode, sortNode, transformer); }
From source file:com.pros.jsontransform.sort.ArraySortDescending.java
public static void sort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) throws ObjectTransformerException { // check $ascending arguments if (sortNode.get(ArraySort.$DESCENDING.name().toLowerCase()).get(ArraySort.ARGUMENT_BY) == null) { throw new ObjectTransformerException( "Missing argument " + ArraySort.ARGUMENT_BY + " in sort directive " + sortNode.toString()); }/* w ww. j a v a 2 s .c o m*/ doSort(arrayNode, sortNode, transformer); }
From source file:ru.gkpromtech.exhibition.organizations.OrganizationFilesDownloader.java
public static void download(final Context context, final Organization organization) { final ProgressDialog dialog = ProgressDialog.show(context, context.getString(R.string.please_wait), context.getString(R.string.loading_materials_info), false); ServiceClient.getJson("organizations/files?id=" + organization.id, new Callback<JsonNode>() { @Override/* www. j ava2 s .c o m*/ public void onSuccess(JsonNode data) throws Exception { dialog.dismiss(); String url = data.get("url").asText(); int size = data.get("size").asInt(); confirmAndDownload(context, organization, url, size); } @Override public void onError(Throwable exception) { dialog.dismiss(); Toast.makeText(context, R.string.error_loading_data, Toast.LENGTH_SHORT).show(); } }); }
From source file:com.meetingninja.csse.database.BaseDatabaseAdapter.java
protected static void logError(final String tag, final JsonNode errorNode) { Log.e(tag, String.format("ErrorID: [%s] %s", errorNode.get(Keys.ERROR_ID).asText(), errorNode.get(Keys.ERROR_MESSAGE).asText())); }
From source file:com.pros.jsontransform.constraint.ConstraintRequired.java
public static void validate(final JsonNode constraintNode, final JsonNode resultNode, final ObjectTransformer transformer) throws ObjectTransformerException { boolean required = constraintNode.get(Constraint.$REQUIRED.toString()).asBoolean(); if (required == true && resultNode.isMissingNode()) { throw new ObjectTransformerException("Constraint violation [" + Constraint.$REQUIRED.toString() + "]" + " on transform node " + transformer.getTransformNodeFieldName()); }// w ww . j av a 2 s. com }
From source file:io.amient.examples.wikipedia.WikipediaMessage.java
public static KeyValue<String, WikipediaMessage> parceIRC(JsonNode time, JsonNode jsonIRCMessage) { try {/*from ww w .ja v a2 s.c om*/ WikipediaMessage edit = WikipediaMessage.parseText(jsonIRCMessage.get("message").textValue()); return new KeyValue<>(edit.user, edit); } catch (IllegalArgumentException e) { return new KeyValue<>(null, null); } }