JsonValue fetchJson(final JsonValue json, final String path) { if (json instanceof JsonObject) { final JsonObject jo = (JsonObject) json; final int ix = path.indexOf("."); if (-1 == ix) { return jo.get(path); } else { final String hd = path.substring(0, ix); final String tl = path.substring(ix + 1); return this.fetchJson(jo.get(hd), tl); } } else { return null; } }
/** * Returns the <code>double</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>double</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public double getDouble(String name, double defaultValue) { JsonValue value=get(name); return value!=null ? value.asDouble() : defaultValue; }
/** * Returns the <code>String</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one is picked. If this * member's value does not represent a JSON string, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public String getString(String name, String defaultValue) { JsonValue value=get(name); return value!=null ? value.asString() : defaultValue; }
/** * Returns the <code>String</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one is picked. If this * member's value does not represent a JSON string, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public String getString(String name, String defaultValue) { JsonValue value=get(name); return value!=null ? value.asString() : defaultValue; }
/** * Returns the <code>int</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>int</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public int getInt(String name, int defaultValue) { JsonValue value=get(name); return value!=null ? value.asInt() : defaultValue; }
/** * Returns the <code>long</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>long</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public long getLong(String name, long defaultValue) { JsonValue value=get(name); return value!=null ? value.asLong() : defaultValue; }
/** * Returns the <code>float</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>float</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public float getFloat(String name, float defaultValue) { JsonValue value=get(name); return value!=null ? value.asFloat() : defaultValue; }
/** * Returns the <code>double</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>double</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public double getDouble(String name, double defaultValue) { JsonValue value=get(name); return value!=null ? value.asDouble() : defaultValue; }
/** * Returns the <code>boolean</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON <code>true</code> or <code>false</code> value, an * exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public boolean getBoolean(String name, boolean defaultValue) { JsonValue value=get(name); return value!=null ? value.asBoolean() : defaultValue; }
/** * Returns the <code>int</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>int</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public int getInt(String name, int defaultValue) { JsonValue value=get(name); return value!=null ? value.asInt() : defaultValue; }
/** * Returns the <code>float</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>float</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public float getFloat(String name, float defaultValue) { JsonValue value=get(name); return value!=null ? value.asFloat() : defaultValue; }
/** * Returns the <code>boolean</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON <code>true</code> or <code>false</code> value, an * exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public boolean getBoolean(String name, boolean defaultValue) { JsonValue value=get(name); return value!=null ? value.asBoolean() : defaultValue; }
/** * Returns the <code>long</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>long</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public long getLong(String name, long defaultValue) { JsonValue value=get(name); return value!=null ? value.asLong() : defaultValue; }
private boolean equals(String key, JsonObject conditions, String value) { return !conditions.names().contains(key) || value.equalsIgnoreCase(conditions.get(key).asString()); }
JsonValue text = json.get("text"); if (text != null) { cc.setText(text.asString()); JsonValue translate = json.get("translate"); if (translate != null) { cc.setTranslate(translate.asString()); JsonValue with = json.get("with"); if (with != null) { JsonArray array = with.asArray(); JsonValue score = json.get("score"); if (score != null) { JsonObject scoreArray = score.asObject(); cc.setScoreUsername(scoreArray.get("name").asString()); cc.setScoreObjective(scoreArray.get("objective").asString()); JsonValue selector = json.get("selector"); if (selector != null) { cc.setSelector(selector.asString()); JsonValue extra = json.get("extra"); if (extra != null) { JsonArray array = extra.asArray(); JsonValue bold = json.get("bold"); if (bold != null) { cc.setBold(bold.asBoolean());
Object convertJsonToJava(final JsonValue value) throws PersistentStoreException { if (null == value) { return null; } else if (value.isString()) { return value.asString(); } else if (value.isNumber()) { return value.asDouble(); } else if (value.isBoolean()) { return value.asBoolean(); } else if (value.isArray()) { final List<Object> list = new ArrayList<>(); for (final JsonValue av : value.asArray()) { final Object o = this.convertJsonToJava(av); list.add(o); } return list; } else if (value.isObject()) { final Map<String, Object> map = new HashMap<>(); for (final String k : value.asObject().names()) { final JsonValue jv = value.asObject().get(k); final Object v = this.convertJsonToJava(jv); map.put(k, v); } return map; } else { throw new PersistentStoreException("Unknown JSON type.", null); } }
final Map<String, Object> map = new HashMap<>(); for (final String k : value.asObject().names()) { final JsonValue jv = value.asObject().get(k); final Object v = this.convertJsonToJava(jv); map.put(k, v);