List of utility methods to do Json Get
JsonObject | getJsonObject(JsonObject object, String name) get Json Object if (hasKey(object, name)) { return object.getJsonObject(name); return null; |
JsonValue | getJsonValue(String json_path, JsonObject response) get Json Value StringTokenizer tk = new StringTokenizer(json_path, "/"); JsonValue rValue = response; JsonObject value = response; while (tk.hasMoreTokens()) { String key = tk.nextToken(); rValue = value.get(key); if (rValue == null || (rValue.getValueType() != ValueType.OBJECT)) { break; ... |
String | getKeyAsString(JsonObject obj, String key, String defaultValue) get Key As String String value = defaultValue; if (obj.containsKey(key)) { value = obj.get(key).toString(); return value; |
long | getLongProperty(JsonObject object, String property) get Long Property return object.getJsonNumber(property).longValue();
|
JsonWriterFactory | getPrettyJsonWriterFactory() get Pretty Json Writer Factory if (null == FACTORY_INSTANCE) { final Map<String, Object> properties = new HashMap<>(1); properties.put(JsonGenerator.PRETTY_PRINTING, true); FACTORY_INSTANCE = Json.createWriterFactory(properties); return FACTORY_INSTANCE; |
JsonArray | getSitesFromDb(String replicationSitesInDB) The reason this in JSON is that it probably makes sense to someday query RSAL or some other "big data" component live for a list of remotes sites to which a particular dataset is replicated to. JsonArrayBuilder arraybuilder = Json.createArrayBuilder(); if (replicationSitesInDB == null || replicationSitesInDB.isEmpty()) { return arraybuilder.build(); String[] sites = replicationSitesInDB.split(","); for (String site : sites) { String[] parts = site.split(":"); arraybuilder.add(Json.createObjectBuilder().add("fqdn", parts[0]).add("name", parts[1]).add("country", ... |
String | getString(JsonObject jso, String name) Gets a string value. if (jso != null && jso.containsKey(name) && !jso.isNull(name)) { JsonValue v = jso.get(name); if (v.getValueType().equals(ValueType.STRING)) { return jso.getString(name); } else if (v.getValueType().equals(ValueType.NUMBER)) { return null; ... |
String | getValueFromJson(JsonObject currentJsonObject, String key) get Value From Json String result = ""; if (currentJsonObject.containsKey(key)) { switch (currentJsonObject.get(key).getValueType()) { case STRING: result = currentJsonObject.getString(key); break; case NUMBER: result = String.valueOf(currentJsonObject.getInt(key)); ... |