JsonArray to Java List Gson Library

suggest change

Here is a simple JsonArray which you would like to convert to a Java ArrayList:

    "list": [

Now pass the JsonArray ‘list’ to the following method which returns a corresponding Java ArrayList:

public ArrayList<String> getListString(String jsonList){
    Type listType = new TypeToken<List<String>>() {}.getType();
    //make sure the name 'list' matches the name of 'JsonArray' in your 'Json'.
    ArrayList<String> list = new Gson().fromJson(jsonList, listType);    
    return list;

You should add the following maven dependency to your POM.xml file:

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->

Or you should have the jar com.google.code.gson:gson:jar:<version> in your classpath.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents