Support handlers for unknown properties, useful for error handling
See original GitHub issueWhat 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:
Issue Analytics
- State:
- Created 9 years ago
- Reactions:9
- Comments:33 (1 by maintainers)
Top Results From Across the Web
failing on unknown properties w/notification - Stack Overflow
The DeserializationProblemHandler class seems to do what you want. It allows you to implement this method to handle unknown properties:
Read more >Best Practices for Node.js Error-handling - Toptal
This article will introduce you to error-handling in Node.js and demonstrate some of the best ... A good example is to try to...
Read more >Error handling - Apollo GraphQL Docs
To help with debugging, Apollo Server provides an ApolloServerErrorCode enum, which you can use to check if your error is one of the...
Read more >Complete Guide to Exception Handling in Spring Boot
A catch-all handler method is also be a good place to log exceptions as they might give insight into a possible bug. We...
Read more >A Guide to Error Handling in Express.js | Scout APM Blog
Handling Custom Errors. Express's default error-handling middleware is super helpful for beginners to take care of unexpected, unhandled errors.
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
I manage to workaround this issue using a class similar to the following:
Do we have this fix as part of the GSON library now ?