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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -