On 7/10/06, Chris Hostetter <[EMAIL PROTECTED]> wrote:
: You don't get complete name preservation (but if that is what you
: wanted, you wouldn't have been using NamedList without names)
so what happens if i have the following in my NamedList...
key: null value:1
key: null value:2
key: "" value:3
key: " 1" value:4
With the NamedList->straight JSON Object
{ "":1, " 1":2, " 3":3, " 4":4}
With "option 3" you get
[ {"":1}, {"":2}, {"":3}, {" 1":4} ]
With "modified option 3", not using objects if the name is null, we get
[ 1, 2, {"":3}, {" 1":4} ]
: > Why not output NamedLists a JSON object?
:
: ??? I currently am... that's the problem. A JSON object is basically
: a map, with no ordering semantics of it's keys.
sorry, i ment making the primary container of the JSON be an object "{}"
instead of an array/list "[]" as you mentioned you were currently using.
Something like this perhaps...
{ "names":[null,null,""," 1"], "values":[1,2,3,4] }
Yes, that's another option...
: Perhaps for the top level NamedList only, I should convert directly
: into a JSON object (preserving the example mapping I gave), and all
: other NamedLists could be the array-of-JSON objects?
I think preserving ordering in the top level response NamedList is just as
important as any other NamedList - perhaps more so since it's the ony most
people interact with.
It's only important if a custom request handler adds info that is
dependent on order.
Stock responses should be fine...
My only concern about your "option 3" is that JSON objects/maps don't
allow null keys, so clients wouldn't be able to distinguish NamedList
enteries with no key vs enteries with empty string keys.
In practise, I'm not sure if the corner cases are that important...
this is only going to affect existing custom query handlers, (and
falling back to XML is always an option). Future custom query
handlers can avoid null keys if they actually need to distinguish null
from "" for some reason.
Both "modified option 3", and your "names+values arrays" preserve
NamedList semantics, at the cost of being ugly and harder to use.
Maybe if I allow people to choose with a flag or something...
-Yonik