diff --git a/Source/ACE.Common/ConfigManager.cs b/Source/ACE.Common/ConfigManager.cs index de0630cf62..8e9f2e8ddd 100644 --- a/Source/ACE.Common/ConfigManager.cs +++ b/Source/ACE.Common/ConfigManager.cs @@ -61,7 +61,7 @@ public static void Initialize(string path = @"Config.js") var fileText = File.ReadAllText(pathToUse); - Config = JsonSerializer.Deserialize(fileText, new JsonSerializerOptions { ReadCommentHandling = JsonCommentHandling.Skip, NumberHandling = JsonNumberHandling.AllowReadingFromString }); + Config = JsonSerializer.Deserialize(fileText, SerializerOptions); } catch (Exception exception) { @@ -72,5 +72,13 @@ public static void Initialize(string path = @"Config.js") throw; } } + + public static JsonSerializerOptions SerializerOptions = new JsonSerializerOptions + { + AllowTrailingCommas = true, + NumberHandling = JsonNumberHandling.AllowReadingFromString, + ReadCommentHandling = JsonCommentHandling.Skip, + WriteIndented = true + }; } } diff --git a/Source/ACE.Server/Factories/StarterGearFactory.cs b/Source/ACE.Server/Factories/StarterGearFactory.cs index d248cb70af..4c2a8a2f68 100644 --- a/Source/ACE.Server/Factories/StarterGearFactory.cs +++ b/Source/ACE.Server/Factories/StarterGearFactory.cs @@ -2,8 +2,8 @@ using System.IO; using System.Reflection; using System.Text.Json; -using System.Text.Json.Serialization; +using ACE.Common; using ACE.Server.Entity; using log4net; @@ -36,7 +36,7 @@ private static StarterGearConfiguration LoadConfigFromResource() { var starterGearText = File.ReadAllText(starterGearFile); - config = JsonSerializer.Deserialize(starterGearText, new JsonSerializerOptions { ReadCommentHandling = JsonCommentHandling.Skip, NumberHandling = JsonNumberHandling.AllowReadingFromString }); + config = JsonSerializer.Deserialize(starterGearText, ConfigManager.SerializerOptions); return config; } diff --git a/Source/ACE.Server/Mods/ModContainer.cs b/Source/ACE.Server/Mods/ModContainer.cs index 11cbd8ad9f..6aeb25ceb6 100644 --- a/Source/ACE.Server/Mods/ModContainer.cs +++ b/Source/ACE.Server/Mods/ModContainer.cs @@ -1,3 +1,5 @@ +using ACE.Common; + using log4net; using McMaster.NETCore.Plugins; @@ -204,7 +206,7 @@ private bool TryCreateModInstance() public void SaveMetadata() { - var json = JsonSerializer.Serialize(Meta, new JsonSerializerOptions { WriteIndented = true }); + var json = JsonSerializer.Serialize(Meta, ConfigManager.SerializerOptions); var info = new FileInfo(MetadataPath); if (!info.RetryWrite(json)) diff --git a/Source/ACE.Server/Mods/ModManager.cs b/Source/ACE.Server/Mods/ModManager.cs index fe9316de31..45607937d5 100644 --- a/Source/ACE.Server/Mods/ModManager.cs +++ b/Source/ACE.Server/Mods/ModManager.cs @@ -1,3 +1,4 @@ +using ACE.Common; using ACE.Server.Managers; using ACE.Server.WorldObjects; @@ -9,7 +10,6 @@ using System.Linq; using System.Text; using System.Text.Json; -using System.Text.Json.Serialization; namespace ACE.Server.Mods { @@ -144,7 +144,7 @@ private static bool TryLoadModContainer(string metadataPath, out ModContainer co try { - var metadata = JsonSerializer.Deserialize(File.ReadAllText(metadataPath), new JsonSerializerOptions { ReadCommentHandling = JsonCommentHandling.Skip, NumberHandling = JsonNumberHandling.AllowReadingFromString }); + var metadata = JsonSerializer.Deserialize(File.ReadAllText(metadataPath), ConfigManager.SerializerOptions); container = new ModContainer() { diff --git a/Source/ACE.Server/Program_Setup.cs b/Source/ACE.Server/Program_Setup.cs index a483d42851..4735d8f699 100644 --- a/Source/ACE.Server/Program_Setup.cs +++ b/Source/ACE.Server/Program_Setup.cs @@ -3,7 +3,6 @@ using System.IO.Compression; using System.Linq; using System.Text.Json; -using System.Text.Json.Serialization; using System.Threading; using ACE.Common; @@ -38,7 +37,7 @@ private static void DoOutOfBoxSetup(string configFile) } var fileText = File.ReadAllText(configFile); - config = JsonSerializer.Deserialize(fileText, new JsonSerializerOptions { ReadCommentHandling = JsonCommentHandling.Skip, NumberHandling = JsonNumberHandling.AllowReadingFromString }); + config = JsonSerializer.Deserialize(fileText, ConfigManager.SerializerOptions); } Console.WriteLine("Performing setup for ACEmulator..."); @@ -260,7 +259,7 @@ private static void DoOutOfBoxSetup(string configFile) Console.WriteLine("commiting configuration to disk..."); - var jsonString = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true }); + var jsonString = JsonSerializer.Serialize(config, ConfigManager.SerializerOptions); File.WriteAllText(configFile, jsonString);