admin
2019-03-13 33b4ed2bbf28ec16b66e552680f56a691a4e908d
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
package com.yeshi.fanli.util;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.adapter.UserInfoAdapter;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import org.yeshi.utils.JsonUtil;
 
public class GsonUtil {
 
    public static String toDFJson(Object obj) {
 
        return new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create()
                .toJson(obj);
    }
 
    public static String toJson(Object obj) {
        Gson gson = new Gson();
        return gson.toJson(obj);
    }
 
    public static String toJsonExpose(Object obj) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        return gson.toJson(obj);
    }
 
    public static String toJsonByUserAp(Object obj) {
        GsonBuilder gsonBuilder = JsonUtil.getConvertBigDecimalToStringBuilder(new GsonBuilder());
        Gson gson = gsonBuilder.excludeFieldsWithoutExposeAnnotation()
                .registerTypeAdapter(UserInfo.class, new UserInfoAdapter()).create();
        return gson.toJson(obj);
    }
 
}