| package com.zy.acs.common.utils; | 
|   | 
| import com.google.gson.Gson; | 
| import com.google.gson.JsonSyntaxException; | 
| import com.google.gson.reflect.TypeToken; | 
| import java.lang.reflect.Type; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| public class GsonUtils { | 
|   | 
|     // include cache | 
|     private static final Gson gson = new Gson(); | 
|   | 
|     public static String toJson(Object object) { | 
|         return gson.toJson(object); | 
|     } | 
|   | 
|     public static <T> T fromJson(String json, Class<T> clazz) throws JsonSyntaxException { | 
|         return gson.fromJson(json, clazz); | 
|     } | 
|   | 
|     public static <T> T fromJson(String json, Type typeOfT) throws JsonSyntaxException { | 
|         return gson.fromJson(json, typeOfT); | 
|     } | 
|   | 
|     public static <T> List<T> fromJsonToList(String json, Class<T> clazz) throws JsonSyntaxException { | 
|         Type type = TypeToken.getParameterized(List.class, clazz).getType(); | 
|         return gson.fromJson(json, type); | 
|     } | 
|   | 
|     public static <K, V> Map<K, V> fromJsonToMap(String json, Class<K> keyType, Class<V> valueType) throws JsonSyntaxException { | 
|         Type type = TypeToken.getParameterized(Map.class, keyType, valueType).getType(); | 
|         return gson.fromJson(json, type); | 
|     } | 
|   | 
| } |