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

1111. appearing after print sequence - php -

excel - I can't get the attachement of the email PHP -

node.js - Express and Redis - If session exists for this user, don't allow access -