fwq
2022-12-26 217258891f8d90a0586a1d785b9ce72f7e226666
提交 | 用户 | age
5c5945 1 /*
E 2  * Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
3  */
4 package com.hx.util;
5
6 import com.google.gson.Gson;
7 import com.google.gson.GsonBuilder;
8 import com.google.gson.JsonParseException;
9
10 import java.lang.reflect.Type;
11
12 /**
13  * Json工具类.
14  */
15 public class GsonUtils {
16     private static Gson gson = new GsonBuilder().create();
17
18     public static String toJson(Object value) {
19         return gson.toJson(value);
20     }
21
22     public static <T> T fromJson(String json, Class<T> classOfT) throws JsonParseException {
23         return gson.fromJson(json, classOfT);
24     }
25
26     public static <T> T fromJson(String json, Type typeOfT) throws JsonParseException {
27         return (T) gson.fromJson(json, typeOfT);
28     }
29 }