[Json-rpc-java] SetSerializer

Michael Clark michael at metaparadigm.com
Tue Apr 17 16:34:47 SGT 2007


rzo wrote:
> Currently SetSerializer serializes set data using JSONObject.
> Therefore string presentation of new HashSet().add("a") returns
> {set: {"a":"a"}}

Yes, its a bit kludgey.

I think I had done this so we had efficient hash lookup behaviour on the
JS side (which is one reason why I use Set in Java). It could in fact
have been {set: {"a":true}} which is a bit nicer (I can't remember the
reasoning behind having the string in the value).

> A more natural way would be to serialize the data using JSONArray.
> This will return:
> {set:["a"]}

Does look simpler.

Although I don't think we can get the hash lookup behaviour with JS
Arrays? it would be a linear search and we'd have to write a loop to
check for existence in the Set.

The JS Array native implementation internal [[get]] method takes an
integer of the array offset and does not respond like a property lookup
on a regular Object (at least not in FireFox AFAICT).

Perhaps an alternative implementation of SetSerializer that can be
chosen with a configuration switch defaulting to off would be okay.

Unless we changed the client de-serialization to scan for sets and
convert them to objects - that is another approach (currently the client
is still using simple eval variable assignment for JSON decoding).

Personally I have a lot of code that uses the lookup function of Sets as
JS Objects.

Michael.


More information about the Json-rpc-java mailing list