google / google/gson

Support handlers for unknown properties, useful for error handling

Open
#188 25 comments 14 reactions 0 assignees View on GitHub
auto-migrated enhancement Priority-Critical Type-Enhancement
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

```
What steps will reproduce the problem?
1. create a JSON string containing extra attributes
2. invoke Gson.fromJson supplying a class with fewer elements
3. GSON successfully instantiates the class without protesting about the
existence of extra attributes in the string.

What is the expected output? What do you see instead?
1. define class A containing two fields: name and surname
2. define class B containing only one field: name
3. transform an instance of class A to Json string and use the Json string
to create an instance of class B.

GSON doesn't complain. Even if this is the intended behavior, shouldn't
there be an option to enforce stricter parsing?

What version of the product are you using? On what operating system?
gson-1.4

Please provide any additional information below.

```

Original issue reported on code.google.com by `mperdik...@gmail.com` on 22 Jan 2010 at 10:13

Attachments:
- [Converter.java](https://storage.googleapis.com/google-code-attachments/google-gson/issue-188/comment-0/Converter.java)

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.