Java Code Examples for com.eclipsesource.json.JsonValue#isObject()
The following examples show how to use
com.eclipsesource.json.JsonValue#isObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZCashClientCaller.java From zencash-swing-wallet-ui with MIT License | 6 votes |
private void decomposeJSONValue(String name, JsonValue val, Map<String, String> map) { if (val.isObject()) { JsonObject obj = val.asObject(); for (String memberName : obj.names()) { this.decomposeJSONValue(name + "." + memberName, obj.get(memberName), map); } } else if (val.isArray()) { JsonArray arr = val.asArray(); for (int i = 0; i < arr.size(); i++) { this.decomposeJSONValue(name + "[" + i + "]", arr.get(i), map); } } else { map.put(name, val.toString()); } }
Example 2
Source File: R2ServerClient.java From r2cloud with Apache License 2.0 | 6 votes |
private static Long readObservationId(String con) { JsonValue result; try { result = Json.parse(con); } catch (ParseException e) { LOG.info("malformed json"); return null; } if (!result.isObject()) { LOG.info("malformed json"); return null; } JsonObject resultObj = result.asObject(); String status = resultObj.getString("status", null); if (status == null || !status.equalsIgnoreCase("SUCCESS")) { LOG.info("response error: {}", resultObj); return null; } long id = resultObj.getLong("id", -1); if (id == -1) { return null; } return id; }
Example 3
Source File: TestUtil.java From r2cloud with Apache License 2.0 | 6 votes |
public static void assertJson(JsonObject expected, JsonObject actual) { StringBuilder message = new StringBuilder(); for (String name : expected.names()) { JsonValue value = actual.get(name); if (value == null) { message.append("missing field: " + name).append("\n"); continue; } if (expected.get(name).isObject() && value.isObject()) { assertJson(expected.get(name).asObject(), value.asObject()); continue; } String expectedValue = expected.get(name).toString(); String actualValue = value.toString(); if (!actualValue.equals(expectedValue)) { message.append("field: \"" + name + "\" expected: " + expectedValue + " actual: " + actualValue + "\n"); } } if (message.length() > 0) { fail(message.toString().trim()); } }
Example 4
Source File: ProActiveVersionUtility.java From scheduling with GNU Affero General Public License v3.0 | 6 votes |
protected static String handleResponse(HttpResponse response) throws IOException { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { HttpEntity entity = response.getEntity(); if (entity != null) { JsonValue jsonValue = Json.parse(EntityUtils.toString(entity)); if (jsonValue.isObject()) { JsonObject jsonObject = jsonValue.asObject(); return jsonObject.get("rest").asString(); } } } return null; }
Example 5
Source File: BoxAuthentication.java From box-android-sdk with Apache License 2.0 | 6 votes |
/** * Load auth info from storage. * * @param context context here is only used to load shared pref. In case you don't need shared pref, you can ignore this * argument in your implementation. * @return a map of all known user authentication information with keys being userId. */ protected ConcurrentHashMap<String, BoxAuthenticationInfo> loadAuthInfoMap(Context context) { ConcurrentHashMap<String, BoxAuthenticationInfo> map = new ConcurrentHashMap<>(); String json = context.getSharedPreferences(AUTH_STORAGE_NAME, 0).getString(AUTH_MAP_STORAGE_KEY, ""); if (json.length() > 0) { BoxEntity obj = new BoxEntity(); obj.createFromJson(json); for (String key: obj.getPropertiesKeySet()) { JsonValue value = obj.getPropertyValue(key); BoxAuthenticationInfo info = null; if (value.isString()) { info = new BoxAuthenticationInfo(); info.createFromJson(value.asString()); } else if (value.isObject()){ info = new BoxAuthenticationInfo(); info.createFromJson(value.asObject()); } map.put(key, info); } } return map; }
Example 6
Source File: JsonRunner_Test.java From minimal-json with MIT License | 6 votes |
private boolean equalsIgnoreOrder(JsonObject object1, JsonValue value2) { if (!value2.isObject()) { return false; } JsonObject object2 = value2.asObject(); List<String> names1 = object1.names(); List<String> names2 = object2.names(); if (!names1.containsAll(names2) || !names2.containsAll(names1)) { return false; } for (String name : names1) { if (!equalsIgnoreOrder(object1.get(name), object2.get(name))) { return false; } } return true; }
Example 7
Source File: ZCashClientCaller.java From zencash-swing-wallet-ui with MIT License | 5 votes |
private JsonObject executeCommandAndGetJsonObject(String command1, String command2) throws WalletCallException, IOException, InterruptedException { JsonValue response = this.executeCommandAndGetJsonValue(command1, command2); if (response.isObject()) { return response.asObject(); } else { throw new WalletCallException("Unexpected non-object response from wallet: " + response.toString()); } }
Example 8
Source File: WebServer.java From r2cloud with Apache License 2.0 | 5 votes |
private static ModelAndView processPost(IHTTPSession session, HttpContoller controller) { ModelAndView model; JsonValue request; try { request = Json.parse(WebServer.getRequestBody(session)); if (!request.isObject()) { model = new BadRequest("expected object"); } else { model = controller.doPost(request.asObject()); } } catch (ParseException e) { model = new BadRequest("expected json object"); } return model; }
Example 9
Source File: TslintHelper.java From typescript.java with MIT License | 5 votes |
private static Location createLocation(JsonValue value) { if (value == null || !value.isObject()) { return null; } JsonObject loc = value.asObject(); return new Location(loc.getInt("line", -1), loc.getInt("character", -1), loc.getInt("position", -1)); }
Example 10
Source File: BoxJsonObject.java From box-android-sdk with Apache License 2.0 | 5 votes |
public <T extends BoxJsonObject> T getAsJsonObject(BoxJsonObjectCreator<T> creator, final String field){ if (mInternalCache.get(field) != null){ return (T)mInternalCache.get(field); } JsonValue value = getAsJsonValue(field); if (value == null || value.isNull() || !value.isObject()) { return null; } T entity = creator.createFromJsonObject(value.asObject()); mInternalCache.put(field, entity); return entity; }
Example 11
Source File: RecipeJson.java From Cubes with MIT License | 5 votes |
public static ItemStack parseStack(JsonValue json) { if (json.isString()) { return new ItemStack(getItem(json.asString())); } else if (json.isObject()) { JsonObject obj = json.asObject(); JsonValue id = obj.get("id"); if (id == null) throw new JsonException("No id"); return new ItemStack(getItem(id.asString()), obj.getInt("count", 1), obj.getInt("meta", 0)); } else if (json.isNull()) { return null; } throw new JsonException("Invalid type " + json.toString()); }
Example 12
Source File: BlockJson.java From Cubes with MIT License | 5 votes |
private static <T> T[] parseMetaElement(JsonObject json, String name, T[] t, MetaElementParser<T> parser) { JsonValue j = json.get(name); if (j == null) return null; if (!j.isObject() || t.length == 1) { Arrays.fill(t, parser.parse(j)); } else { JsonObject jsonObject = j.asObject(); T defaultT = null; for (Member member : jsonObject) { String s = member.getName(); if (s.equals("default")) { defaultT = parser.parse(member.getValue()); continue; } int m = -1; try { m = Integer.parseInt(s); t[m] = null; // catch out of range exceptions } catch (Exception e) { throw new JsonException("Unexpected " + name + " member \"" + member.getName() + "\""); } t[m] = parser.parse(member.getValue()); } for (int i = 0; i < t.length; i++) { if (t[i] == null) { if (defaultT == null) { throw new JsonException(name + " for meta " + i + " not defined"); } else { t[i] = defaultT; } } } } return t; }
Example 13
Source File: ObjectJsonRule.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void validate(JsonValue value) { if (!value.isObject()) { throw new IllegalArgumentException(value + " is not an object."); } JsonObject object = value.asObject(); Set<String> names = new HashSet<>(object.names()); for (Entry<String, JsonRule> entry : rules.entrySet()) { entry.getValue().validate(object.get(entry.getKey())); names.remove(entry.getKey()); } if (!names.isEmpty()) { throw new IllegalArgumentException(String.format("%s does not have a rule.", names.iterator().next())); } }
Example 14
Source File: JsonRunner_Test.java From minimal-json with MIT License | 5 votes |
private boolean equalsIgnoreOrder(JsonValue value1, JsonValue value2) { if (value1.isObject()) { return equalsIgnoreOrder(value1.asObject(), value2); } else if (value1.isArray()) { return equalsIgnoreOrder(value1.asArray(), value2); } return value1.equals(value2); }
Example 15
Source File: Observation.java From r2cloud with Apache License 2.0 | 4 votes |
public static Observation fromJson(JsonObject meta) { Observation result = new Observation(); result.setId(meta.getString("id", null)); result.setStartTimeMillis(meta.getLong("start", -1L)); result.setEndTimeMillis(meta.getLong("end", -1L)); result.setOutputSampleRate(meta.getInt("sampleRate", -1)); result.setInputSampleRate(meta.getInt("inputSampleRate", -1)); result.setSatelliteFrequency(meta.getLong("frequency", -1)); result.setActualFrequency(meta.getLong("actualFrequency", -1)); result.setBandwidth(meta.getLong("bandwidth", -1)); String decoder = meta.getString("decoder", null); if ("aausat4".equals(decoder)) { decoder = "telemetry"; } if (decoder != null) { result.setSource(FrequencySource.valueOf(decoder.toUpperCase(Locale.UK))); } result.setSatelliteId(meta.getString("satellite", null)); JsonValue tle = meta.get("tle"); if (tle != null && tle.isObject()) { result.setTle(Tle.fromJson(tle.asObject())); } JsonValue groundStation = meta.get("groundStation"); if (groundStation != null && groundStation.isObject()) { result.setGroundStation(groundStationFromJson(groundStation.asObject())); } result.setGain(meta.getString("gain", null)); result.setChannelA(meta.getString("channelA", null)); result.setChannelB(meta.getString("channelB", null)); result.setNumberOfDecodedPackets(meta.getLong("numberOfDecodedPackets", 0)); result.setaURL(meta.getString("aURL", null)); result.setDataURL(meta.getString("data", null)); result.setSpectogramURL(meta.getString("spectogramURL", null)); result.setRawURL(meta.getString("rawURL", null)); String statusStr = meta.getString("status", null); if (statusStr != null) { result.setStatus(ObservationStatus.valueOf(statusStr)); } else { result.setStatus(ObservationStatus.UPLOADED); } return result; }