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