yuwei5380 / jsonplugin

Automatically exported from code.google.com/p/jsonplugin
0 stars 0 forks source link

Map with complex objects as keys results in broken JSON #93

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

I assume that this JSON is broken, as reported by syntax checker
(http://www.jslint.com):

{{"field1":"key1","field2":"key2"}:"value1"}

This JSON is the way JSON Plugin serializes a Map with a key of two-fields
Java Bean.

I'm eager to fix that, but have no idea how to map Maps with complex keys
to JSON...

Original issue reported on code.google.com by omikh...@gmail.com on 18 May 2009 at 2:42

GoogleCodeExporter commented 8 years ago
Just checked DWR for this case.
It logs this warning:

org.directwebremoting.convert.MapConverter :warn :: --Javascript does not 
support non
string keys. Converting 'B' using toString()

and puts that toString as a key, which results in a valid JSON String.
DWR approach is better than the JSON Plugin's one, but still not perfect.
Can we produce a JSON that would be valid, would not effect other values in the 
Map
and would contain the data from the key object?

Original comment by omikh...@gmail.com on 18 May 2009 at 4:48

GoogleCodeExporter commented 8 years ago
Committed changes to JSONWriter
Not it serializes Map keys using toString() and logs a warning if key is not a 
String
I couldn't find any way to keep the key data in JSON

toString() is also required to process Map keys b/c shouldExcludePropert method 
takes
expression based on key.toString()

Original comment by omikh...@gmail.com on 18 May 2009 at 6:34