mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Replace JSON.NET with System.Text.json (#840)
This commit is contained in:
1 parent
e112ca9da8
commit
a340f8822e
63 files changed
+466
-584
No files matched your search
+8
-8
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared.DataModelVisualization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display;
|
||||
|
||||
@@ -11,16 +12,15 @@ namespace Artemis.UI.Shared.DefaultTypes.DataModel.Display;
|
||||
/// </summary>
|
||||
internal class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel<object>
|
||||
{
|
||||
private readonly JsonSerializerSettings _serializerSettings;
|
||||
private readonly JsonSerializerOptions _serializerSettings;
|
||||
private string _display;
|
||||
|
||||
public DefaultDataModelDisplayViewModel()
|
||||
{
|
||||
_serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
PreserveReferencesHandling = PreserveReferencesHandling.None
|
||||
};
|
||||
_serializerSettings = CoreJson.GetJsonSerializerOptions();
|
||||
_serializerSettings.ReferenceHandler = ReferenceHandler.IgnoreCycles;
|
||||
_serializerSettings.WriteIndented = true;
|
||||
|
||||
_display = "null";
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ internal class DefaultDataModelDisplayViewModel : DataModelDisplayViewModel<obje
|
||||
if (DisplayValue is Enum enumDisplayValue)
|
||||
Display = EnumUtilities.HumanizeValue(enumDisplayValue);
|
||||
else if (DisplayValue is not string)
|
||||
Display = JsonConvert.SerializeObject(DisplayValue, _serializerSettings);
|
||||
Display = JsonSerializer.Serialize(DisplayValue, _serializerSettings);
|
||||
else
|
||||
Display = DisplayValue?.ToString() ?? "null";
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@ public static class ClipboardExtensions
|
||||
public static async Task<T?> GetJsonAsync<T>(this IClipboard clipboard, string format)
|
||||
{
|
||||
byte[]? bytes = (byte[]?) await clipboard.GetDataAsync(format);
|
||||
return bytes == null ? default : CoreJson.DeserializeObject<T>(Encoding.Unicode.GetString(bytes), true);
|
||||
return bytes == null ? default : CoreJson.Deserialize<T>(Encoding.Unicode.GetString(bytes).TrimEnd('\0'));
|
||||
}
|
||||
}
|
||||
@@ -32,12 +32,12 @@ public class ResetLayerProperty<T> : IProfileEditorCommand
|
||||
/// <inheritdoc />
|
||||
public void Execute()
|
||||
{
|
||||
string json = CoreJson.SerializeObject(_layerProperty.DefaultValue, true);
|
||||
string json = CoreJson.Serialize(_layerProperty.DefaultValue);
|
||||
|
||||
if (_keyframesEnabled)
|
||||
_layerProperty.KeyframesEnabled = false;
|
||||
|
||||
_layerProperty.SetCurrentValue(CoreJson.DeserializeObject<T>(json)!);
|
||||
_layerProperty.SetCurrentValue(CoreJson.Deserialize<T>(json)!);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in new issue
Block a user