1234567891011121314151617181920212223242526272829 |
- /*
- * Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
- */
- package com.miniframe.tools;
- import com.google.gson.Gson;
- import com.google.gson.GsonBuilder;
- import com.google.gson.JsonParseException;
- import java.lang.reflect.Type;
- /**
- * Json工具类.
- */
- public class XIGsonUtils {
- private static Gson gson = new GsonBuilder().create();
- public static String toJson(Object value) {
- return gson.toJson(value);
- }
- public static <T> T fromJson(String json, Class<T> classOfT) throws JsonParseException {
- return gson.fromJson(json, classOfT);
- }
- public static <T> T fromJson(String json, Type typeOfT) throws JsonParseException {
- return (T) gson.fromJson(json, typeOfT);
- }
- }
|