Repository navigation
Is it expected for GSON to not serialize some data when using generics? #3074
Replies: 2 comments
|
Yes, this is expected for the declared field type. I ran your sample unchanged with Gson 2.12.1. The output was:
If the field is always a |
|
This is due to Gson's internal So the behavior is probably intended, but might not be ideal for all use cases. A workaround can be to have a custom Note however that if you also have to deserialize the data again, then when using the runtime type for serialization you probably also need custom deserialization logic to pick the correct |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello. I noticed that when I have a field with a generic type, GSON does not serialize the extra fields of the child class. If I let it raw, it works fine. Is this expected behaviour or should I open an issue?
All reactions