Open GoogleCodeExporter opened 9 years ago
As yonmost pointed out in issue 524, if the Integer is a value instead of key
then it works as expected. I swapped the Integer and String in the data map
above, and got this expected output:
[
{
"Hello": 4
}
]
Original comment by vivienne...@google.com
on 19 Aug 2014 at 5:32
My colleague pointed out that JSON keys have to be Strings. Would it be
possible then to add documentation in toJson so the end user doesn't get
confused when trying to parse the JSON back into a Map?
Original comment by vivienne...@google.com
on 19 Aug 2014 at 5:58
You should use
new Gson().toJson(data, new TypeToken<Map<Integer, String>>() {}.getType())
Otherwise, gson can't know what kind of map you want.
http://google-gson.googlecode.com/svn/tags/1.1.1/docs/javadocs/com/google/gson/r
eflect/TypeToken.html
Original comment by Maaarti...@gmail.com
on 27 Aug 2014 at 3:54
"new Gson().toJson(data, new TypeToken<Map<Integer, String>>() {}.getType())"
The above method is not work.
Original comment by androida...@gmail.com
on 31 Dec 2014 at 4:15
Original issue reported on code.google.com by
vivienne...@google.com
on 19 Aug 2014 at 5:29