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);
|
}
|
|
}
|