@Deprecated public static JSONObject getJsonObject(String json) { if (!isNull(json)) if (json.trim().startsWith("{")) try { return EwJsonObject.parse(json); } catch (JSONException je) { } return null; }
@Override public boolean isNull(Object ref) { return (ref == null || EwJson.isNull(this.opt(ref))); }
@Override public boolean isNull(Object ref) { return (ref == null || EwJson.isNull(this.opt(ref))); }
@Deprecated public static JSONArray getJsonArray(String json) { if (!isNull(json)) if (json.trim().startsWith("[")) try { return EwJsonArray.parse(json); } catch (JSONException je) { } return null; }
/** * Overridden to first try parsing value as an EwJsonCollection. All puts * executed in the parent call this method. Null values result in the * removal of any existing value at key. */ @Override public synchronized EwJsonObject put(String key, Object value) throws JSONException { Object wrapped = EwJson.wrap(value); orderedKeys.add(key); if (EwJson.isNull(wrapped)) super.put(key, (Object) null); else super.put(key, wrapped); return this; }
/** * Overridden to first try wrapping as a valid JSON value. All index-based * puts in parent call this method. All index-based puts also pad the * underlying {@link ArrayList} with null values when index is beyond the * current range of the array. */ @Override public EwJsonArray put(int index, Object value) throws JSONException { Object wrapped = EwJson.wrap(value); if (EwJson.isNull(wrapped)) super.put(index, (Object) null); else super.put(index, wrapped); return this; }
@Deprecated public static Object tryReduce(Object object, boolean nullify) { if (isNull(object)) return null; if (object instanceof JSONArray) return reduce((JSONArray) object); if (object instanceof JSONObject) return reduce((JSONObject) object); return (nullify) ? null : object; }
/** Overridden for a more thorough null check. */ @Override public boolean isNull(int index) { return super.isNull(index) || EwJson.isNull(this.opt(index)); }
/** * Compares this with object, after it has been wrapped by * {@link EwJson#wrap(Object)}. */ @Override public boolean equals(Object object) { if (super.equals(object)) return true; final Object wrapped = EwJson.wrap(object); if (this == wrapped) return true; if (EwJson.isNull(wrapped)) return false; if (wrapped instanceof EwJsonCollection) return EwJson.equals(this, (EwJsonCollection) wrapped); return false; }
/** * Compares this with object, after it has been wrapped by * {@link EwJson#wrap(Object)}. */ @Override public boolean equals(Object object) { if (super.equals(object)) return true; final Object wrapped = EwJson.wrap(object); if (this == wrapped) return true; if (EwJson.isNull(wrapped)) return false; if (wrapped instanceof EwJsonCollection) return EwJson.equals(this, (EwJsonCollection) wrapped); return false; }
public EwJsonArray putOnce(int index, Object value) throws JSONException { final Object existing = super.opt(index); if (!EwJson.isNull(existing)) throw new JSONException("Duplicate index \"" + index + "\""); return this.put(index, value); }
@Override public EwJsonObject putOnce(Object ref, Object value) throws JSONException { final Object existing = this.opt(ref); if (!EwJson.isNull(existing)) throw new JSONException("Duplicate key \"" + (String) ref + "\""); return this.put(ref, value); }
@Deprecated public static Object tryParseJson(Object object, boolean nullify, boolean reduce) { if (isNull(object)) return null; final JSONArray ja = getInstanceOfJsonArray(object); if (ja != null) return (reduce) ? tryReduce(ja, nullify) : ja; final JSONObject jo = getInstanceOfJsonObject(object); if (jo != null) return (reduce) ? tryReduce(jo, nullify) : jo; return (nullify) ? null : object; }
@Deprecated public static String valueToString(Object value) throws JSONException { if (isNull(value)) return "null"; if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) return value.toString(); if (value instanceof Number) { validateDecimal(value); String string = value.toString(); if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) { int length = string.length(); while (string.charAt(length - 1) == '0') length--; if (string.charAt(length - 1) == '.') length--; string = string.substring(0, length); } return string; } if (value instanceof Map) return new EwJsonObject((Map<?, ?>) value).toString(); if (value instanceof Collection) return new EwJsonArray((Collection<?>) value).toString(); if (value.getClass().isArray()) return new EwJsonArray(value).toString(); return JSONObject.quote(value.toString()); }
if (EwJson.isNull(source)) return;
@Deprecated public static Object derefComplexKey(Object object, String key) throws JSONException { if (isNull(object)) return null; if (!isComplexKey(key)) return getElement(object, key); final EwList<Object> results = processComplexKey(object, KEY_PATTERN.split(key)); switch (results.size()) { case 0: return null; case 1: return results.get(0); default: return results; } }
/** * Attempt to merge any object with this. * * @see #merge(Object) * @param source * Object to attempt to use to populate this array. * @throws JSONException * Malformed object. */ public EwJsonObject(Object source) throws JSONException { this(); if (EwJson.isNull(source)) return; else if (source instanceof JSONObject) { EwJson.merge(this, (JSONObject) source); } else if (source instanceof String) { EwJsonObject.mergeFromString(this, (String) source, null); } else { EwJsonObject.tryMergeAny(this, source, null); } }
if (!EwJson.isNull(from))
if (!EwJson.isNull(from))
@Deprecated public static EwJsonCollection accumulate(EwJsonCollection json, Object ref, Object value) throws JSONException { if (json == null) return null; validateDecimal(value); final Object object = json.opt(ref); if (EwJson.isNull(object)) { // First JSONArray in the slot is wrapped, to prevent accumulation // to it later json.putOpt(ref, (value instanceof JSONArray) ? new EwJsonArray().put(value) : value); } else if (object instanceof JSONArray) { // Later items in the slot are accumulated to an existing JSONArray EwJsonArray.convert((JSONArray) object).put(value); } else { // Slot contains a non-accumulated value, wrap it in an array and // append to it json.putOpt(ref, ((new EwJsonArray()).put(object)).put(value)); } return json; }