Closed GoogleCodeExporter closed 9 years ago
The reason Gson doesn't allow custom handlers for Map Keys is because the key
needs to
be a valid field name (it can not be a Json object, for example). Allowing
arbitrary
handlers can result in invalid JSON being produced.I understand that using
toString()
is probably unnaturally limited, but supporting serializers is not a good idea.
Any
other proposals?
Original comment by inder123
on 2 Jun 2009 at 5:46
Yes, this was quick and dirty support custom serializers as it expects (JSON)
String to be returned from the
serializers; I see two other possible solutions, either have the key objects
implement something like JsonMapKey
interface with String asMapKey() method, or have specialized type for custom
map key serializers. One thing to
note is that deserialization for custom map key objects is currently supported,
so one would hope that
serialization would be supported trough the same mechanism.
Overall this is not a big issue as one can implement toString() method and
preform serialization there...
Original comment by zregv...@gmail.com
on 3 Jun 2009 at 12:56
The reason we do not support serialization is because we do not want to output
invalid
JSON. Deserialization is supported to be more permissive in what input we
accept.
Original comment by inder123
on 3 Jun 2009 at 5:46
Original comment by inder123
on 23 Sep 2009 at 7:08
Original issue reported on code.google.com by
zregv...@gmail.com
on 31 May 2009 at 6:30Attachments: