package com.th.demo.tools;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.th.demo.model.system.ResponseCodeMsg;
import com.th.demo.model.system.ResultJSON;

public class JSONTools {
    public   static  String toString(Object object){
        ResultJSON  result =  new ResultJSON(ResponseCodeMsg.CODE_OK, ResponseCodeMsg.MSG_OK, object);
        return JSON.toJSONString(result,SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
    }
    public   static  String toString(int exCode,String exMessage){
        ResultJSON  result =  new ResultJSON(exCode, exMessage, null);
        return JSON.toJSONString(result,SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
    }
    public  static  String toString(Object object,String format){
        ResultJSON  result =  new ResultJSON(ResponseCodeMsg.CODE_OK, ResponseCodeMsg.MSG_OK, object);
        return JSON.toJSONStringWithDateFormat(result,format,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
    }
    public  static  String toStringyyyyMMdd(Object object){
        ResultJSON  result =  new ResultJSON(ResponseCodeMsg.CODE_OK, ResponseCodeMsg.MSG_OK, object);
        return JSON.toJSONStringWithDateFormat(result,"yyyy-MM-dd",SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
    }
    public  static  String toStringyyyyMMddHHmmss(Object object){
        ResultJSON  result =  new ResultJSON(ResponseCodeMsg.CODE_OK, ResponseCodeMsg.MSG_OK, object);
        return JSON.toJSONStringWithDateFormat(result,"yyyy-MM-dd HH:mm:ss",SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullBooleanAsFalse);
    }
}
