Gson does not detect duplicate keys in the nested json
See original GitHub issueGson is unable detect duplicate keys in the nested json
See below code snippet
public static void main(String[] args) throws IOException {
Map<String, ?> map;
//this does not detect duplicate 'key'
map = new Gson().fromJson("{'a':'x','aa':{'key':'x','key':'y'}}", Map.class);
//As expected , this call fails with Exception in thread "main" com.google.gson.JsonSyntaxException: duplicate key: a
map = new Gson().fromJson("{'a':'x','a':'y'}", Map.class);
}
Is this the expected behavior ? If so is there any alternative to fail in the first case as well?
Issue Analytics
- State:
- Created 8 years ago
- Comments:10
Top Results From Across the Web
Make Gson throw exception on parsing JSON with duplicated ...
I want it to throw some exception. I know I can parse JSON as map, and then Gson throws exception in such case,...
Read more >Gson does not detect duplicate keys in the nested json
Gson is unable detect duplicate keys in the nested json. See below code snippet public static void main(String[] args) throws IOException ...
Read more >Parsing between JSON and Kotlin Object with Google Gson ...
In this tutorial I will discuss about how to parse a class object into json string and convert it back from json string...
Read more >An Exploration of JSON Interoperability Vulnerabilities
Even within the official JSON RFC, there is open-ended guidance on a few topics, such as how to handle duplicate keys and represent...
Read more >How do you handle duplicate keys in JSON? - Quora
No. A map cannot have duplicate keys. You access the value associated with the unique key using operator[] (i.e., square brackets). You would...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please add a option, which can be set to not allow duplicate keys.
Don’t have any hope, Google is against the devs. Again.