/** * Construct a JSONObject from a Map. * * Note: Use this constructor when the map contains <key,bean>. * * @param map - A map with Key-Bean data. * @param includeSuperClass - Tell whether to include the super class properties. */ public JSONObject(final Map map, final boolean includeSuperClass) { this.map = new HashMap(); if (map != null) { Iterator i = map.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = (Map.Entry)i.next(); if (JSONObject.isStandardProperty(e.getValue().getClass())) { this.map.put(e.getKey(), e.getValue()); } else { this.map.put(e.getKey(), new JSONObject(e.getValue(), includeSuperClass)); } } } }
/** * Construct a JSONObject from a Map. * * Note: Use this constructor when the map contains <key,bean>. * * @param map - A map with Key-Bean data. * @param includeSuperClass - Tell whether to include the super class properties. */ public JSONObject(final Map map, final boolean includeSuperClass) { this.map = new HashMap(); if (map != null) { Iterator<Map.Entry> i = map.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = i.next(); if (JSONObject.isStandardProperty(e.getValue().getClass())) { this.map.put(e.getKey(), e.getValue()); } else { this.map.put(e.getKey(), new JSONObject(e.getValue(), includeSuperClass)); } } } }
/** * Construct a JSONArray from a collection of beans. * The collection should have Java Beans. */ public JSONArray(final Collection collection, final boolean includeSuperClass) { myArrayList = collection == null ? new ArrayList<Object>() : new ArrayList<Object>(collection.size()); if (collection != null) { Iterator<Object> iter = collection.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof Map<?, ?>) { myArrayList.add(new JSONObject((Map<?, ?>)o, includeSuperClass)); } else if (!JSONObject.isStandardProperty(o.getClass())) { myArrayList.add(new JSONObject(o, includeSuperClass)); } else { myArrayList.add(o); } } } }
/** * Construct a JSONArray from a collection of beans. * The collection should have Java Beans. * * @throws JSONException If not an array. */ public JSONArray(final Collection collection, final boolean includeSuperClass) { myArrayList = new ArrayList(); if (collection != null) { Iterator iter = collection.iterator();; while (iter.hasNext()) { Object o = iter.next(); if (o instanceof Map) { myArrayList.add(new JSONObject((Map)o, includeSuperClass)); } else if (!JSONObject.isStandardProperty(o.getClass())) { myArrayList.add(new JSONObject(o, includeSuperClass)); } else { myArrayList.add(o); } } } }
/** * Construct a JSONArray from an array with a bean. * The array should have Java Beans. * * @throws JSONException If not an array. */ public JSONArray(final Object array, final boolean includeSuperClass) throws JSONException { this(); if (array.getClass().isArray()) { int length = Array.getLength(array); for (int i = 0; i < length; i += 1) { Object o = Array.get(array, i); if (JSONObject.isStandardProperty(o.getClass())) { myArrayList.add(o); } else { myArrayList.add(new JSONObject(o, includeSuperClass)); } } } else { throw new JSONException("JSONArray initial value should be a string or collection or array."); } }
/** * Construct a JSONArray from an array with a bean. * The array should have Java Beans. * * @throws JSONException If not an array. */ public JSONArray(final Object array, final boolean includeSuperClass) throws JSONException { this(); if (array.getClass().isArray()) { int length = Array.getLength(array); for (int i = 0; i < length; i += 1) { Object o = Array.get(array, i); if (JSONObject.isStandardProperty(o.getClass())) { myArrayList.add(o); } else { myArrayList.add(new JSONObject(o, includeSuperClass)); } } } else { throw new JSONException("JSONArray initial value should be a string or collection or array."); } }
else if (JSONObject.isStandardProperty(result.getClass()))
else if (JSONObject.isStandardProperty(result.getClass()))