java - Gson gives "unchecked conversion" warning -


i trying convert json strings objects this:

string jsonstring = "[\"string1\", \"string2\"]"; gson gson = new gson(); list<string> list = gson.fromjson(jsonstring, list.class); 

there warning:

warning: [unchecked] unchecked conversion             list = gson.fromjson(jsonstring, list.class);                                        ^   required: list<string>   found:    list 

i tried use list<string>.class

instead of list.class compile time error saying can't that...

how can rid of warning?

you can use array

string[] array = gson.fromjson(jsonstring, string[].class); 

or using typetoken

type listtype = new typetoken<arraylist<string>>() {}.gettype(); list<string> list  = gson.fromjson(jsonstring, listtype); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -