public static T GetObject <T>(this byte[] source, JsonCompressLevel compress = JsonCompressLevel.None, bool camelCase = true, bool withChinese = true, bool nameCaseInsensitive = true) where T : class, IUseLNJsonExtends { if (source == null) { return(null); } switch (compress) { case JsonCompressLevel.High: case JsonCompressLevel.Normal: return(JsonSerializer.Deserialize <T>(Core.TextTools.BrotliUTF8.GetString(source), GetOptions(camelCase, withChinese, nameCaseInsensitive))); case JsonCompressLevel.None: default: return(JsonSerializer.Deserialize <T>(Encoding.UTF8.GetString(source), GetOptions(camelCase, withChinese, nameCaseInsensitive))); } }
public static byte[] GetBytes <T>(this T target, JsonCompressLevel compress = JsonCompressLevel.None, bool camelCase = true, bool withChinese = true, bool nameCaseInsensitive = true, JsonSerializerOptions options = null) where T : class, IUseLNJsonExtends { if (target == null) { return(null); } if (options == null) { options = GetOptions(camelCase, withChinese, nameCaseInsensitive); } switch (compress) { case JsonCompressLevel.Normal: return(Core.TextTools.BrotliUTF8.Compress(JsonSerializer.Serialize(target, options))); case JsonCompressLevel.High: return(Core.TextTools.BrotliUTF8.CompressHightLevel(JsonSerializer.Serialize(target, options))); case JsonCompressLevel.None: default: return(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(target, options))); } }