Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import com.google.gson.Gson;

import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.util.ArrayList;

public class Main {
    private static Gson gson;

    public static <T> ArrayList<T> toObjectList(String json, Class<T> type) {
        if (json == null) {
            return null;
        }
        JsonReader reader = new JsonReader(new StringReader(json));
        reader.setLenient(true);
        Type gsonType = new TypeToken<ArrayList<T>>() {
        }.getType();
        return (ArrayList<T>) gson.fromJson(reader, gsonType);
    }
}