google / google/gson

Gson does not detect duplicate keys in the nested json

Open
#647 10 comments 0 reactions 1 assignee Claimed by @inder123 View on GitHub
enhancement
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

Gson is unable detect duplicate keys in the nested json

See below code snippet

```
public static void main(String[] args) throws IOException {
Map 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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.