From 8ff0e59206839bfd2479d4d0a3b94a7d0483885a Mon Sep 17 00:00:00 2001 From: Ian Wold <1645320+IanWold@users.noreply.github.com> Date: Mon, 15 Aug 2022 17:00:32 -0500 Subject: [PATCH] Replace Newtonsoft with Utf8Json (#15) --- Metalsharp/Metalsharp.csproj | 2 +- Metalsharp/MetalsharpFile.cs | 4 +--- Metalsharp/MetalsharpProject.cs | 4 +++- Metalsharp/Plugins/Branch/Branch.cs | 7 +++---- Metalsharp/Plugins/Frontmatter/Frontmatter.cs | 3 ++- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Metalsharp/Metalsharp.csproj b/Metalsharp/Metalsharp.csproj index f652a5d..19e4530 100644 --- a/Metalsharp/Metalsharp.csproj +++ b/Metalsharp/Metalsharp.csproj @@ -29,8 +29,8 @@ + - diff --git a/Metalsharp/MetalsharpFile.cs b/Metalsharp/MetalsharpFile.cs index e56021e..7dde401 100644 --- a/Metalsharp/MetalsharpFile.cs +++ b/Metalsharp/MetalsharpFile.cs @@ -1,5 +1,4 @@ -using Newtonsoft.Json; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; namespace Metalsharp; @@ -48,7 +47,6 @@ public class MetalsharpFile /// /// The metadata of the file, stored as a string, object dictionary. /// - [JsonConstructor] public MetalsharpFile(string text, string filePath, Dictionary metadata) { Text = text; diff --git a/Metalsharp/MetalsharpProject.cs b/Metalsharp/MetalsharpProject.cs index 0ed6f53..e513ea6 100644 --- a/Metalsharp/MetalsharpProject.cs +++ b/Metalsharp/MetalsharpProject.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.Serialization; using Metalsharp.Logging; namespace Metalsharp; @@ -82,7 +83,8 @@ public MetalsharpProject(MetalsharpConfiguration configuration = null) /// /// The logger. /// - [Newtonsoft.Json.JsonIgnore] + //[Newtonsoft.Json.JsonIgnore] + [IgnoreDataMember] public Log Log => _log ??= new Log(Configuration.Verbosity); private Log _log; diff --git a/Metalsharp/Plugins/Branch/Branch.cs b/Metalsharp/Plugins/Branch/Branch.cs index 3ab766a..c4450b1 100644 --- a/Metalsharp/Plugins/Branch/Branch.cs +++ b/Metalsharp/Plugins/Branch/Branch.cs @@ -1,8 +1,7 @@ -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.Linq; -using static Newtonsoft.Json.JsonConvert; +using Utf8Json; namespace Metalsharp; @@ -53,7 +52,7 @@ public Branch(params Action[] branches) => /// public void Execute(MetalsharpProject project) => _branches.ForEach(b => { - var projectClone = DeserializeObject(SerializeObject(project)); + var projectClone = JsonSerializer.Deserialize(JsonSerializer.Serialize(project)); projectClone.Log.Debug("Executing new branch"); b(projectClone); diff --git a/Metalsharp/Plugins/Frontmatter/Frontmatter.cs b/Metalsharp/Plugins/Frontmatter/Frontmatter.cs index cf9f5b5..5d90aba 100644 --- a/Metalsharp/Plugins/Frontmatter/Frontmatter.cs +++ b/Metalsharp/Plugins/Frontmatter/Frontmatter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Utf8Json; namespace Metalsharp; @@ -181,7 +182,7 @@ private static bool TryGetJsonFrontmatter(string document, out Dictionary>(split[1].Trim()); + var jsonFrontmatter = JsonSerializer.Deserialize>(split[1].Trim()); var arrayRemainder = string.Join(";;;", split.Skip(2)); frontmatter = jsonFrontmatter;