java - google.gson.fromJson where classOfT is generic array -
how deserialize array of generic type gson.fromjson
public class cache<t> { public void m(string json) { jsonarray ja = (jsonarray) new jsonparser().parse(json); gson gson = new gsonbuilder().create(); t[] items = gson.fromjson(ja, ?); } }
this not work
type t = new typetoken<arraylist<t>>() {}.gettype(); t[] items = gson.fromjson(ja, t);
t[] items = gson.fromjson(ja, t[].class);
t[] items = gson.fromjson(ja, new t[].getclass());
t[] array = (t[]) array.newinstance(clazz, 0); t[] result = gson.fromjson(jsonstring, (type) array.getclass()); list<t> resultlist = arrays.aslist(result);
Comments
Post a Comment