/** * Construct a JsonObject from a Map. * <p/> * 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(Map<Object, Object> map, boolean includeSuperClass) { this.map = new HashMap<Object, Object>(); if (map != null) { Iterator<Map.Entry<Object, Object>> i = map.entrySet().iterator(); while (i.hasNext()) { Map.Entry<Object, Object> e = i.next(); if (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. * * @throws JsonException If not an array. */ public JsonArray(Collection<?> collection, boolean includeSuperClass) { this.myArrayList = new ArrayList<Object>(); if (collection != null) { Iterator<?> iter = collection.iterator(); ; while (iter.hasNext()) { Object o = iter.next(); if (o instanceof Map<?, ?>) { this.myArrayList.add(new JsonObject((Map<?, ?>) o, includeSuperClass)); } else if (!JsonObject.isStandardProperty(o.getClass())) { this.myArrayList.add(new JsonObject(o, includeSuperClass)); } else { this.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(Object array, 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())) { this.myArrayList.add(o); } else { this.myArrayList.add(new JsonObject(o, includeSuperClass)); } } } else { throw new JsonException("JsonArray initial value should be a string or collection or array."); } }
} else if (result instanceof Map<?, ?>) { map.put(key, new JsonObject((Map<?, ?>) result, includeSuperClass)); } else if (isStandardProperty(result.getClass())) { // Primitives,