make json writer class use built-in json parsing code instead of newtonsoft.json
This commit is contained in:
parent
fa59624172
commit
b47769b290
@ -1,9 +1,10 @@
|
||||
using Common.Models.Output;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Common.Models.Input;
|
||||
using System.Text.Json;
|
||||
using System.Text.Unicode;
|
||||
using System.Text.Encodings.Web;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
@ -12,6 +13,11 @@ namespace Common
|
||||
private readonly string _workingPath;
|
||||
private readonly string _outputFolderName;
|
||||
|
||||
private static JsonSerializerOptions ignoreNullOptions = new JsonSerializerOptions
|
||||
{
|
||||
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
|
||||
WriteIndented = true};
|
||||
|
||||
public JsonWriter(string workingPath, string outputFolderName)
|
||||
{
|
||||
_workingPath = workingPath;
|
||||
@ -23,6 +29,12 @@ namespace Common
|
||||
var outputPath = $"{_workingPath}\\{_outputFolderName}";
|
||||
DiskHelpers.CreateDirIfDoesntExist(outputPath);
|
||||
|
||||
var jsonOptions = new JsonSerializerOptions()
|
||||
{
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
||||
};
|
||||
|
||||
foreach (var bot in bots)
|
||||
{
|
||||
if (bot.appearance.body.Count == 0) // only process files that have data in them, no body = no dumps
|
||||
@ -30,7 +42,7 @@ namespace Common
|
||||
LoggingHelpers.LogToConsole($"Unable to process bot type: {bot.botType}, skipping", ConsoleColor.DarkRed);
|
||||
continue;
|
||||
}
|
||||
var output = JsonConvert.SerializeObject(bot, Formatting.Indented);
|
||||
var output = JsonSerializer.Serialize(bot, jsonOptions);
|
||||
Console.WriteLine($"Writing json file {bot.botType} to {outputPath}");
|
||||
File.WriteAllText($"{outputPath}\\{bot.botType.ToString().ToLower()}.json", output);
|
||||
Console.WriteLine($"file {bot.botType} written to {outputPath}");
|
||||
@ -42,10 +54,7 @@ namespace Common
|
||||
var outputPath = $"{_workingPath}\\{_outputFolderName}";
|
||||
DiskHelpers.CreateDirIfDoesntExist(outputPath);
|
||||
|
||||
var output = JsonConvert.SerializeObject(bots, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
});
|
||||
var output = JsonSerializer.Serialize(bots, ignoreNullOptions);
|
||||
File.WriteAllText($"{outputPath}\\{fileName.ToLower()}.json", output);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user