: > 2) we should try to ensure that trivial parsing of the format of a
: > NamedList should preserve the order -- if we have to "lose information" in
: > the convertion, i would rather throw away the "name" for each item (and
: > treat the list as a JSON "array"
:
: People will disagree on that one I am sure... NamedList is both like a
: List and a Map, and some will want to use it either way.

If the orriginal data (from the RequestHandler) truely had no ordering to
it, then it could have been added to the response as Map -- if it's a
NamedList it's got order and i think the OutputWriter needs to respect
that.

Returning a List of Pairs may look ugly, but if the clients wants a
simpler "Map" it's easy to convert to that from a List of Pairs --
it's impossible however to convert a Map back to the orriginal List once
the order is lost.

I understand that the OutputWriter isn't throwing away the order ... it's
still writing the data in the orriginal order, but the JSON semantics
effectively make that irrelevent.  Clients would need to explicitly parse
the docs with order in mind, which eliminates the ability to use the
"built in" JSON parsing that makes JSON so appealing.

: Currnetly null is mapped to "", and then run through the normal
: procedure to make sure that key hasn't been used before.  So you could
: end up with "" and " 1"
:
: 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


: > 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] }

: After going over this again, I think I'd be OK with option 3 for
: NamedLists, because Maps and Documents can still use the cleaner
: mapping to a single JSON object.
: The remaining problem is that the top level of a QueryResponse is
: modeled as a NamedList.  Does order need to be preserved there?
: 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.

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.

-Hoss

Reply via email to