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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -