I want to parse json data into java object using google-gson.
Here is an example of the data I want to parse:
{\"isBean\":{\"userName\":\"test\",\
The problem is solved With the help of Stackoverflow Answer.
Create gson object:
Gson gson = new GsonBuilder().registerTypeAdapter(IsBean.class, new InterfaceAdapter<IsBean>()).create();
Without seeing the code of CommunicationObject
, I can't say for sure BUT I am guessing with confidence that the class has a field of type IsBean
in which you use it to hold the User
. If so, the problem is that GSON scans fields of the object obj
of the class CommunicationObject
and based on the field definition, the value of the field (which is typed IsBean
) will have to be created BUT since the type is an interface, it can't instance object for that field.
Another words, as JSON field does not specifies the object type, GSON must relies on the defined type of the field to create the instance for the field value which can't be done if the type is an interface.
So, consider changing the type of that field if that make sense to you. OR look into creating InstanceCreator of IsBean
(doute that it is logically possible).
See also: Deserializing an abstract class in Gson
Hope this helps.