using System;
using Newtonsoft.Json;

public static class SerializeUtil
{
    static SerializeUtil()
    {
        JsonConvert.DefaultSettings = () => { return DefaultUseJsonSettings; };
    }

    private static JsonSerializerSettings DefaultUseJsonSettings = new JsonSerializerSettings
    {
        Formatting = Formatting.None,
        DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
        DateFormatString = "yyyy/MM/dd hh:mm:ss",
    };

    private static JsonSerializerSettings JsonIndentedSettings = new JsonSerializerSettings
    {
        Formatting = Formatting.Indented,
        DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
        DateFormatString = "yyyy/MM/dd hh:mm:ss",
    };

    public static string ToJson(object obj)
    {
        return JsonConvert.SerializeObject(obj, DefaultUseJsonSettings);
    }

    public static string ToJsonIndented(object obj)
    {
        return JsonConvert.SerializeObject(obj, JsonIndentedSettings);
    }

    public static string ToJson(object obj, Type type)
    {
        return JsonConvert.SerializeObject(obj, type, DefaultUseJsonSettings);
    }

    public static string ToJson<T>(object obj)
    {
        return ToJson(obj, typeof(T));
    }

    public static T ToObject<T>(string json)
    {
        return JsonConvert.DeserializeObject<T>(json);
    }
}