Example usage for com.google.gson.reflect TypeToken getParameterized

List of usage examples for com.google.gson.reflect TypeToken getParameterized

Introduction

In this page you can find the example usage for com.google.gson.reflect TypeToken getParameterized.

Prototype

public static TypeToken<?> getParameterized(Type rawType, Type... typeArguments) 

Source Link

Document

Gets type literal for the parameterized type represented by applying typeArguments to rawType .

Usage

From source file:io.webfolder.cdp.session.SessionFactory.java

License:Open Source License

public List<SessionInfo> list() {
    String listSessions = format("http://%s:%d/json/list", host, port);
    URL url = null;/*from ww  w  .j a  v a2s .  c  om*/
    Reader reader = null;
    try {
        url = new URL(listSessions);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(connectionTimeout);
        reader = new InputStreamReader(conn.getInputStream());
        TypeToken<?> type = TypeToken.getParameterized(List.class, SessionInfo.class);
        List<SessionInfo> list = gson.fromJson(reader, type.getType());
        return list;
    } catch (IOException e) {
        throw new CdpException(e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}