Java tutorial
//package com.java2s; import java.lang.reflect.Type; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import android.support.annotation.NonNull; public class Main { private static final String JSON_PARSE_ERROR = "Unable to parse JSON: "; private static Gson sGson; private static Gson sExposeGson; public static <T> T fromExposeJson(@NonNull String content, @NonNull Class<T> clazz) throws IllegalStateException { try { return sExposeGson.fromJson(content, clazz); } catch (JsonSyntaxException e) { throw new IllegalStateException(JSON_PARSE_ERROR + content, e); } } public static <T> T fromJson(@NonNull String content, @NonNull Class<T> clazz) throws IllegalStateException { try { return sGson.fromJson(content, clazz); } catch (JsonSyntaxException e) { throw new IllegalStateException(JSON_PARSE_ERROR + content, e); } } public static <T> T fromJson(@NonNull String content, @NonNull Type type) throws IllegalStateException { try { return sGson.fromJson(content, type); } catch (JsonSyntaxException e) { throw new IllegalStateException(JSON_PARSE_ERROR + content, e); } } }