Java Type Generic as Argument for GSON

前端 未结 13 1758
陌清茗
陌清茗 2020-11-27 12:51

In GSON to get a list of objects you do

Gson gson = new Gson();
Type token = new TypeToken>(){}.getType();
return gson.fromJson(json         


        
13条回答
  •  离开以前
    2020-11-27 13:32

    public  List fromJSonList(String json) {
      Gson gson = new Gson();
      Type collectionType = new TypeToken>(){}.getType();
      return gson.fromJson(json, collectionType);
    }
    
    //Just call
    List myTypes = parser.fromJSonList(jsonString);
    

提交回复
热议问题