I didn't quite think the way you can use the new API to create new
JSON objects through. Specifically, in order to support the 'set'
notation, Any given lookup will always need to tree out from the root,
every time, which could be a little slow for very deeply nested JSON,
and take up more memory.

In other words:

JSON json = JSON.parse(/*deeply nested
json*/).get("foo").get("bar").get(10).get("baz");

would have to be just the original deeply nested json and a 'pointer'
to foo/bar/10/baz. So, it will still take up all the memory of the big
json object, and every access to this thing will result internally in:

jso["foo"]["bar"][10]["baz"].

I also have some doubts that the writing part of the API will make
sense to the casual user. It's definitely fast and convenient if you
know how it works, but, does this look readable to you (objective:
create {"foo": [10, null], "bar": []}:


JSON json = JSON.createMap();
json.get("foo").add().set(10);
json.get("foo").add().setNull();
json.get("bar").set(JSON.createList());

(one of the problems is that its really difficult to create empty
lists/maps with this method, as the general idea is to create the
'structure' (JS arrays and objects) on demand, but there is no demand
if they are supposed to be empty!)

Contrast this to the IMHO much cleaner code you can use to read such a
structure:

json.get("foo").get(0).asInt();
json.get("foo").get(1).isNull();
for (json item : JSON.get("foo").asList()) {
  Object o = item.asObject();
}
json.get("bar").asList().size();
json.asObject(); //returns a HashMap with 2 ArrayLists in it, one of
which has an Integer and 'null', the other is empty).


Here's an alternative idea: Let the new API exist only for reading - I
never really had an issue with the existing API's utility when
creating JSON - just when reading it. Solves all these problems. If
that's fine, then it's ready to go right now, pending an addition to
the regexp that finds string literals during the validation step as
per Scott Blum's comments.


--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to