981Re: [json] Sorting the keys of formatted (pretty printed) JSON output
- Apr 10, 2008On Thu, Apr 10, 2008 at 5:13 AM, Arthur Blake <arthur.blake@...> wrote:
> On Thu, Apr 10, 2008 at 12:29 AM, Tatu Saloranta <tsaloranta@...>
> > One question: wouldn't it be easier to just use TreeMap for storing
> > fields, instead of HashMap, if sorting is desired?
> > -+ Tatu +-
> That was my first thought when thinking about how to do it, as well.
> That would make sense if you wanted to always keep and use the JSON
> sorted. In one of my main use cases (JSON-RPC debug output on the
> There would be a penalty for keeping a TreeMap versus a HashMap.I understand this, and it's a valid point. But I was thinking more
> HashMap obviously performs better (constant time put & get) for when
along the lines of deferring initialization of the Map, and switching
between the two if/as necessary. That is, it'd be a property of Json
object, to minimize sorting overhead for cases where it's not needed.
At any rate, I just wanted to mention it as an option, just to make
sure it was considered. And that seems to have been the case.
-+ Tatu +-
- << Previous post in topic Next post in topic >>