mirror of
https://github.com/osukey/osukey.git
synced 2025-07-04 01:40:02 +09:00
Make Beatmap ISerializable and add more JsonIgnores
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.IO.Serialization.Converters;
|
||||
|
||||
namespace osu.Game.IO.Serialization
|
||||
{
|
||||
@ -11,20 +12,21 @@ namespace osu.Game.IO.Serialization
|
||||
|
||||
public static class JsonSerializableExtensions
|
||||
{
|
||||
public static string Serialize(this IJsonSerializable obj)
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
||||
}
|
||||
public static string Serialize(this IJsonSerializable obj) => JsonConvert.SerializeObject(obj, CreateGlobalSettings());
|
||||
|
||||
public static T Deserialize<T>(this string objString)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(objString);
|
||||
}
|
||||
public static T Deserialize<T>(this string objString) => JsonConvert.DeserializeObject<T>(objString, CreateGlobalSettings());
|
||||
|
||||
public static T DeepClone<T>(this T obj)
|
||||
where T : IJsonSerializable
|
||||
public static void DeserializeInto<T>(this string objString, T target) => JsonConvert.PopulateObject(objString, target, CreateGlobalSettings());
|
||||
|
||||
public static T DeepClone<T>(this T obj) where T : IJsonSerializable => Deserialize<T>(Serialize(obj));
|
||||
|
||||
public static JsonSerializerSettings CreateGlobalSettings() => new JsonSerializerSettings
|
||||
{
|
||||
return Deserialize<T>(Serialize(obj));
|
||||
}
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
Formatting = Formatting.Indented,
|
||||
ObjectCreationHandling = ObjectCreationHandling.Replace,
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
||||
Converters = new JsonConverter[] { new Vector2Converter() }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user