Deserializing Generic Types with GSON

前端 未结 5 2050
耶瑟儿~
耶瑟儿~ 2020-11-27 14:46

I have some problems with implementation of Json Deserialization in my Android application (with Gson library)

I\'ve made class like this

public clas         


        
5条回答
  •  一个人的身影
    2020-11-27 15:11

    Have you tried?

    gson.create().fromJson(reader, MyJson.class);
    

    EDIT

    After reading this post it seems that you use of Type is correct. I believe your issue is the use of T. You must remember that with Java there is type-erasure. This means that at runtime all instances of T are replaced with Object. Therefore at runtime what you are passing GSON is really MyJson. If you tried this with a concrete class in place of I believe it would work.

    Google Gson - deserialize list object? (generic type)

    提交回复
    热议问题