mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Remove IJsonSerializable interface
Was pretty pointless and made it hard to use the custom serialisation terms arbitrarily in tests.
This commit is contained in:
28
osu.Game/IO/Serialization/JsonSerializableExtensions.cs
Normal file
28
osu.Game/IO/Serialization/JsonSerializableExtensions.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.IO.Serialization;
|
||||
|
||||
namespace osu.Game.IO.Serialization
|
||||
{
|
||||
public static class JsonSerializableExtensions
|
||||
{
|
||||
public static string Serialize(this object obj) => JsonConvert.SerializeObject(obj, CreateGlobalSettings());
|
||||
|
||||
public static T Deserialize<T>(this string objString) => JsonConvert.DeserializeObject<T>(objString, CreateGlobalSettings());
|
||||
|
||||
public static void DeserializeInto<T>(this string objString, T target) => JsonConvert.PopulateObject(objString, target, CreateGlobalSettings());
|
||||
|
||||
public static JsonSerializerSettings CreateGlobalSettings() => new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
Formatting = Formatting.Indented,
|
||||
ObjectCreationHandling = ObjectCreationHandling.Replace,
|
||||
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
|
||||
Converters = new List<JsonConverter> { new Vector2Converter() },
|
||||
ContractResolver = new KeyContractResolver()
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user