Java Language JSON in Java JsonArray to Java List (Gson Library)

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


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:

<!-- -->

Or you should have the jar<version> in your classpath.

Got any Java Language Question?