admin
2020-06-20 0ab8a2ea521a838124f517daf4e61dee971a6d4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.ks.tool.bkz.util;
 
 
import com.google.gson.*;
import net.sf.json.JSONObject;
 
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.Date;
 
public class JsonUtil {
 
    public static String loadTrueResult(Object data) {
        JSONObject root = new JSONObject();
        root.put("code", 0);
        root.put("data", data);
        return root.toString();
    }
 
    public static String loadFalseResult(int code, String msg) {
        JSONObject root = new JSONObject();
        root.put("code", code);
        root.put("msg", msg);
        return root.toString();
    }
 
 
    public static Gson getSimpleGson(){
        return new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
            @Override
            public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                if (value == null) {
                    return null;
                } else {
                    return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(),"yyyy-MM-dd HH:mm:ss"));
                }
            }
        }).create();
 
    }
 
 
 
}