question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gson fails to parse simple map

See original GitHub issue
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

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
GoogleCodeExportercommented, Mar 19, 2015
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

1reaction
eamonnmcmanuscommented, Sep 10, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue 501 in google-gson: Gson fails to parse simple map
meisen.net: Gson fails to parse simple map http://code.google.com/p/google-gson/issues/detail?id=501. When parsing the following json with gson (using 2.2.2 ...
Read more >
GSON - unable to parse Json to complex POJO having List ...
The reason for the exception is that JsonNode is an abstract class that Gson cannot create a default instance for it.
Read more >
Gson Deserialization Cookbook - Baeldung
In this cookbook, we're exploring the various ways to unmarshall JSON into Java objects, using the popular Gson library. 1. Deserialize JSON to ......
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
The JavaScript exceptions thrown by JSON.parse() occur when string failed to be parsed as JSON.
Read more >
Java Gson - JSON serialization and deserialization ... - ZetCode
It is easy for humans to read and write and for machines to parse and ... Map; public class GsonToJson { public static...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found