2023-07-17 12:24:28 +02:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Text.Encodings.Web;
|
2023-07-17 11:58:05 +02:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Unicode;
|
2023-07-17 10:20:00 +02:00
|
|
|
|
|
|
|
|
|
namespace TaikoSoundEditor
|
|
|
|
|
{
|
|
|
|
|
internal static class Json
|
|
|
|
|
{
|
|
|
|
|
public static T Deserialize<T>(string json)
|
2023-07-19 07:10:25 +02:00
|
|
|
|
{
|
|
|
|
|
Logger.Info($"Deserializing {typeof(T)} ({json.Length})");
|
2023-07-17 10:20:00 +02:00
|
|
|
|
return JsonSerializer.Deserialize<T>(json);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-19 11:07:42 +02:00
|
|
|
|
|
|
|
|
|
public static string Serialize<T>(T item, bool indented = true)
|
2023-07-17 10:20:00 +02:00
|
|
|
|
{
|
2023-07-19 07:10:25 +02:00
|
|
|
|
Logger.Info($"Serializing {typeof(T)}:\n{item}");
|
2023-07-17 11:58:05 +02:00
|
|
|
|
return JsonSerializer.Serialize(item, new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
|
2023-07-19 11:07:42 +02:00
|
|
|
|
WriteIndented = indented
|
2023-07-17 11:58:05 +02:00
|
|
|
|
});
|
2023-07-17 10:20:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|