I
I
Igor2014-10-09 17:24:20
Java
Igor, 2014-10-09 17:24:20

Why is there a deserialization error in Gson if there is a nested class?

There is such a class:

public class CategoriesResponse extends BaseResponse {

 private Data data = new Data();

 public class Data extends ArrayList<Category> implements Serializable {
 }

 public class Category implements Serializable {
  private int id;
  private String name;
  private String icon;
 }
}

when trying to convert a string with json data ( gson.fromJson() ) to a CategoriesResponse object, an error occurs:
"D/dalvikvm﹕ wrong object type: Ljava/util/ArrayList; Lcom/ips/stavki/net/api/categories/CategoriesResponse$ Data;"
If you take out the internal class Data in a separate file, then the deserialization passes without errors. What if you don’t want to make a separate file for the class, I just have a lot of them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bimeg, 2014-10-09
@asdf999

make them public static class....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question