Open SuperPat45 opened 1 month ago
Adding generic in JSONObject and JSONArray, will break old codes, in Java, generics cannot have default types.
I lost hope that one day this code will be valid in JAVA:
public class JSONArray<E = Object> extends ArrayList<E> implements List<E>, JSONAwareEx, JSONStreamAwareEx {
}
Or I need to add some new generics JSONTypedArray<E>
and JSONTypedObject<E>
and implements class JSONArray
by class JSONArray extends JSONTypedArray<Object>
Adding generic in JSONObject and JSONArray, will break old codes
Maybe for a JSON-Smart v3
Can you make JSONArray generic:, so we can write:
JSONArray<JSONObject> array = new JSONArray<JSONObject>();
JSONObject can also be generic for the value:
JSONObject<String> object = new JSONObject<String>();
To remove the need of castings when getting an object or an array, add, in the JSONObject class, two methods getAsObject() and getAsArray() methods:
If the map or the collection is not a JSONObject or JSONArray, the method will convert it.
This can be used easily without cast and throw an Exception if the value is not a map:
JSONObject<String> object = jsonObjectParent.getAsObject("childObject");
Like for an array::