1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package cn.com.qmth.sdk.util;
- import com.google.gson.Gson;
- import com.google.gson.GsonBuilder;
- import cn.com.qmth.sdk.util.DateUtil.DatePatterns;
- /**
- * 类注释
- *
- * @author WANGWEI
- */
- public class JsonUtil {
- /**
- * 方法注释
- *
- * @author WANGWEI
- * @param obj
- * @return
- */
- public static String toJson(Object obj) {
- Gson gson = new GsonBuilder().disableHtmlEscaping().setDateFormat(DatePatterns.ISO)
- .create();
- return gson.toJson(obj);
- }
- /**
- * 方法注释
- *
- * @author WANGWEI
- * @param obj
- * @return
- */
- public static String toPrettyJson(Object obj) {
- Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
- .setDateFormat(DatePatterns.ISO).create();
- return gson.toJson(obj);
- }
- /**
- * 方法注释
- *
- * @author WANGWEI
- * @param json
- * @param c
- * @return
- */
- public static <T> T fromJson(String json, Class<T> c) {
- Gson gson = new GsonBuilder().disableHtmlEscaping().create();
- return gson.fromJson(json, c);
- }
- }
|