-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectTypeAdapter error when the value type is a Number #1257
Comments
Another error I found, is that the ObjectTypeAdapter could not be overriden: neither by extending the class (because it's final) nor by adding another factory to the Gson, because ObjectTypeAdapter is always processed first. |
Gson team is aware of that since its 1st version (9 Sep 2011). |
Maybe we don't want people to be able to override ObjectTypeAdapter or put it second in the list of factories as it could change the default behavior of parsing JSON objects. But can we try out the following way of customizing the behavior of ObjectTypeAdapter? That is, change the following code:
to
And there will be a new function in GsonBuilder like registerObjectNumberReader(NumberReader). The default NumberReader will just call Would this work? I can work on this. Another thing I'd like is to ability to force types based on the path. For example, when parsing |
Fixed by #1290. |
Hi,
I found an error in the read method of the ObjectTypeAdapter when the value is a Number, as it always transforms it to a double value. But maybe the expected value is an Integer. I made the following change, and it seems to work fine:
The text was updated successfully, but these errors were encountered: