gson: gson does not deserialize interfaces, even with an InstanceCreator
What steps will reproduce the problem?
1. Create an interface that defines getters only
2. Create a concrete class that implements the interface, with local fields and
accessors corresponding to the interface
3. Specify an InstanceCreator to create concrete instances of the interface
4. Serialize a concrete instance of the class using gson
5. Deserialize from the JSON string produced in step 4.
What is the expected output? What do you see instead?
Given that an InstanceCreator is specified, I would expect a concrete
implementation of the interface corresponding to the type created in the
InstanceCreator, with the fields set from the JSON string.
Instead, a concrete instance of the class is returned but the fields are NOT
populated.
Using version 2.1
I get that this can be done by creating a custom serializer/deserializer for
the type, but I don't get why that should be required. If so I can just use a
regular JSONObject and do it all myself. Seems like it should be a fairly
simple task. Take the runtime type created by the InstanceCreator, match the
fields in the instance against the values in the JSON string using reflection,
set and repeat.
Am I missing something here?
Original issue reported on code.google.com by jason.po...@gmail.com
on 21 Feb 2012 at 2:33
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 2
- Comments: 15
This issue schould be prioritized. I need it soon 👍
This is a major bug. I have wasted 2 days into this till I came across this page. Google, please solve this problem or at least give an easier workaround