-
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
Gson deserializes wildcards to LinkedHashMap #1107
Comments
…pes (google#1146) * fix issue google#1107: resolve element type in wildcard collection types * fix Codacy warnings * fix Codacy warnings
was this ever fixed/released? I still see the problem even on v2.8.5 |
Could you please test if this still occurs with the latest Gson version? I think #1146 should have fixed this. At least the originally provided sample code seems to work, except that the member name seems to be incorrect: If you still experience this please provide a small self contained example, and mention which Gson version you are using. |
Hi, Im using Gson 2.10.1. I think the issue is still present. I was trying to write a class that can The following is the class for the parser. This takes in a Generic Type.
In the test case below, I was expecting the Gson parser to return a list of the generic type (here TypeA or TypeB). I was expecting this test case to pass but I see that the type returned is actually a
Additional DetailsThese are two data classes and the json file contents that were used in the test case shown above TypeA.kt
TypeB.kt
Type A. json
TypeB.json
|
@mhdsuhail172, that is a different issue. The problem with your code is that it uses You have to make |
@Marcono1234 thank you so much for guiding me to the reified type parameter. This helped solve this . I changed the function to an inline reified function like shown below. Now the type info is present at runtime and its able to deserialize perfectly to TypeA or TypeB.
|
This issue is a successor to #1101.
Models:
Json:
Gson call:
This call will fail with a
ClassCastException
exception –com.google.gson.internal.LinkedTreeMap cannot be cast to Entry
. If we remove? extends
then everything works fine.The text was updated successfully, but these errors were encountered: