gson: Gson fails to parse simple map

When parsing the following json with gson (using 2.2.2 from maven-central), 
gson (fromJson) throws an:

JsonSyntaxException: "duplicate key: null"

whereby the json is created by gson (toJson) itself.

Json:
{"appProperties":{"server.configuration.reset":"false","server.db.jndi":"testDB"
,"xml.basedata.list":"basedata.xml","server.configuration.cache":"false","xml.la
yout.list":"","server.rolemapper":"InsertionRoleMapper","xml.content.list":"data
.xml"}}

http://json.parser.online.fr/ validates the string as correct...

Original issue reported on code.google.com by phil...@meisen.net on 15 Feb 2013 at 12:04

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

I had the same problem but it turns out it was my fault - I had a map like this:

Map<Outcome, Integer> myMap

where Outcome is an enum. However in the enum, toString was not returning the 
name(). 

So GSON could write the JSON ok, but it could not deserialize it, because when 
it tried to create the enum, it didn't know how so it wrote a null, then when 
did this the second time it reported "duplicate key: null"

Original comment by mark.but...@oi-sys.com on 11 Jul 2013 at 4:22

Thanks @TheDoctorOne, that does look suspicious and we should look into it.