开发者

Json conversion using Gson

开发者 https://www.devze.com 2023-02-21 11:59 出处:网络
开发者_StackOverflow中文版Hi I have the following class and need to convert the incoming Json using Gson
开发者_StackOverflow中文版

Hi I have the following class and need to convert the incoming Json using Gson

public class JsonConverter<T>{

private boolean success = Boolean.TRUE;
private List<T> data;
private int total;
private String message;

public JsonConverter(){

}

public JsonConverter(List<T> data, int count){
    this.data = data;
    this.total = count;
} //getters and setters

I have an incoming Json with a data property that contains the values of some a class which has the following definition:

class A {private long calendarId;
private String title;
private String description;
private int colorId;
private boolean isHidden;
private long userId; //getter and setter

}

Example: Json string:

{"data":{"calendarId":"ext-gen223","title":"work","description":"work","isHidden":false,"colorId":"2"}}

I want to get the value from Json String and set it inside the List data (which should be a list of Class A objects) of Class JsonConverter using Gson.

Thanks


Used Type type = new TypeToken<JsonConverter<A>>(){}.getType(); and got it running!

0

精彩评论

暂无评论...
验证码 换一张
取 消