using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;

namespace TEAMModelOS.SDK.Helper.Common.JsonHelper
{
    public static class JsonApiHelper
    {
        static JsonSerializerOptions options = new JsonSerializerOptions()
        {
            WriteIndented = true,                                   //格式化json字符串
            AllowTrailingCommas = true,                             //可以结尾有逗号
            //IgnoreNullValues = true,                              //可以有空值,转换json去除空值属性
            IgnoreReadOnlyProperties = true,                        //忽略只读属性
            PropertyNameCaseInsensitive = true,                     //忽略大小写
            //PropertyNamingPolicy = JsonNamingPolicy.CamelCase     //命名方式是默认还是CamelCase
        };
        public static string ToJson(this object input)
        {
            return JsonSerializer.Serialize(input, options);
        }

        public static T FromJson<T>(this string input)
        {
            return JsonSerializer.Deserialize<T>(input, options);
        }
    }
}
