mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Use System.Text.Json instead of NewtonSoft.Json
This commit is contained in:
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
@@ -9,8 +11,6 @@ using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
using Aaru.Core;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes;
|
||||
|
||||
@@ -115,24 +115,25 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest
|
||||
|
||||
Assert.AreEqual(ErrorNumber.NoError, ret, string.Format(Localization.Unmountable_0, testFile));
|
||||
|
||||
var serializer = new JsonSerializer
|
||||
var serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
MaxDepth = 16384,
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
},
|
||||
MaxDepth = 1536, // More than this an we get a StackOverflowException
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
serializer.Converters.Add(new StringEnumConverter());
|
||||
|
||||
if(test.ContentsJson != null)
|
||||
test.Contents =
|
||||
serializer.
|
||||
Deserialize<
|
||||
Dictionary<string, FileData>>(new JsonTextReader(new StringReader(test.ContentsJson)));
|
||||
JsonSerializer.Deserialize<Dictionary<string, FileData>>(test.ContentsJson, serializerOptions);
|
||||
else if(File.Exists($"{testFile}.contents.json"))
|
||||
{
|
||||
var sr = new StreamReader($"{testFile}.contents.json");
|
||||
test.Contents = serializer.Deserialize<Dictionary<string, FileData>>(new JsonTextReader(sr));
|
||||
var sr = new FileStream($"{testFile}.contents.json", FileMode.Open);
|
||||
test.Contents = JsonSerializer.Deserialize<Dictionary<string, FileData>>(sr, serializerOptions);
|
||||
}
|
||||
|
||||
if(test.Contents is null)
|
||||
@@ -222,17 +223,20 @@ public abstract class ReadOnlyFilesystemTest : FilesystemTest
|
||||
|
||||
Dictionary<string, FileData> contents = BuildDirectory(fs, "/");
|
||||
|
||||
var serializer = new JsonSerializer
|
||||
var serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
MaxDepth = 16384,
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
},
|
||||
MaxDepth = 1536,
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
serializer.Converters.Add(new StringEnumConverter());
|
||||
|
||||
var sw = new StreamWriter($"{testFile}.contents.json");
|
||||
serializer.Serialize(sw, contents);
|
||||
var sw = new FileStream($"{testFile}.contents.json", FileMode.Create);
|
||||
JsonSerializer.Serialize(sw, contents, serializerOptions);
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
@@ -8,8 +10,6 @@ using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Core;
|
||||
using Aaru.Tests.Filesystems;
|
||||
using FluentAssertions.Execution;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Aaru.Tests.Images;
|
||||
@@ -205,18 +205,20 @@ public abstract class BlockMediaImageTest : BaseMediaImageTest
|
||||
if(!File.Exists(expectedDataFilename))
|
||||
continue;
|
||||
|
||||
var serializer = new JsonSerializer
|
||||
var serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
MaxDepth = 16384,
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
},
|
||||
MaxDepth = 1536, // More than this an we get a StackOverflowException
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
serializer.Converters.Add(new StringEnumConverter());
|
||||
|
||||
var sr = new StreamReader(expectedDataFilename);
|
||||
|
||||
VolumeData[] expectedData = serializer.Deserialize<VolumeData[]>(new JsonTextReader(sr));
|
||||
var sr = new FileStream(expectedDataFilename, FileMode.Open);
|
||||
VolumeData[] expectedData = JsonSerializer.Deserialize<VolumeData[]>(sr, serializerOptions);
|
||||
|
||||
Assert.NotNull(expectedData);
|
||||
|
||||
@@ -259,8 +261,8 @@ public abstract class BlockMediaImageTest : BaseMediaImageTest
|
||||
};
|
||||
}
|
||||
|
||||
var sw = new StreamWriter(expectedDataFilename);
|
||||
serializer.Serialize(sw, expectedData);
|
||||
var sw = new FileStream(expectedDataFilename, FileMode.Create);
|
||||
JsonSerializer.Serialize(sw, expectedData, serializerOptions);
|
||||
sw.Close();
|
||||
*/
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes;
|
||||
@@ -13,8 +15,6 @@ using Aaru.Core;
|
||||
using Aaru.Tests.Filesystems;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Execution;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Aaru.Tests.Images;
|
||||
@@ -251,29 +251,31 @@ public abstract class OpticalMediaImageTest : BaseMediaImageTest
|
||||
Assert.AreEqual(ErrorNumber.NoError, ret,
|
||||
string.Format(Localization.Unmountable_0, testFile));
|
||||
|
||||
var serializer = new JsonSerializer
|
||||
var serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
MaxDepth = 16384,
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
},
|
||||
MaxDepth = 1536, // More than this an we get a StackOverflowException
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
serializer.Converters.Add(new StringEnumConverter());
|
||||
|
||||
if(track.FileSystems[i].ContentsJson != null)
|
||||
track.FileSystems[i].Contents =
|
||||
serializer.
|
||||
Deserialize<
|
||||
Dictionary<string, FileData>>(new JsonTextReader(new StringReader(track.
|
||||
FileSystems[i].
|
||||
ContentsJson)));
|
||||
JsonSerializer.
|
||||
Deserialize<Dictionary<string, FileData>>(track.FileSystems[i].ContentsJson,
|
||||
serializerOptions);
|
||||
else if(File.Exists($"{testFile}.track{track.Number}.filesystem{i}.contents.json"))
|
||||
{
|
||||
var sr = new StreamReader($"{testFile}.track{track.Number}.filesystem{i
|
||||
}.contents.json");
|
||||
var sr =
|
||||
new FileStream($"{testFile}.track{track.Number}.filesystem{i}.contents.json",
|
||||
FileMode.Open);
|
||||
|
||||
track.FileSystems[i].Contents =
|
||||
serializer.Deserialize<Dictionary<string, FileData>>(new JsonTextReader(sr));
|
||||
JsonSerializer.Deserialize<Dictionary<string, FileData>>(sr, serializerOptions);
|
||||
}
|
||||
|
||||
if(track.FileSystems[i].Contents is null)
|
||||
@@ -285,8 +287,8 @@ public abstract class OpticalMediaImageTest : BaseMediaImageTest
|
||||
// Uncomment to generate JSON file
|
||||
/* var contents = ReadOnlyFilesystemTest.BuildDirectory(rofs, "/");
|
||||
|
||||
var sw = new StreamWriter($"{testFile}.track{track.Number}.filesystem{i}.contents.json");
|
||||
serializer.Serialize(sw, contents);
|
||||
var sw = new FileStream($"{testFile}.track{track.Number}.filesystem{i}.contents.json", FileMode.Create);
|
||||
JsonSerializer.Serialize(sw, contents, serializerOptions);
|
||||
sw.Close();*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Aaru.Checksums;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
@@ -9,8 +11,6 @@ using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.CommonTypes.Structs;
|
||||
using Aaru.Core;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes;
|
||||
|
||||
@@ -75,17 +75,20 @@ public abstract class FsExtractHashIssueTest
|
||||
|
||||
Assert.True(File.Exists($"{TestFile}.unittest.json"));
|
||||
|
||||
var serializer = new JsonSerializer
|
||||
var serializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
MaxDepth = 16384,
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
},
|
||||
MaxDepth = 1536, // More than this an we get a StackOverflowException
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
serializer.Converters.Add(new StringEnumConverter());
|
||||
|
||||
var sr = new StreamReader($"{TestFile}.unittest.json");
|
||||
FsExtractHashData expectedData = serializer.Deserialize<FsExtractHashData>(new JsonTextReader(sr));
|
||||
var sr = new FileStream($"{TestFile}.unittest.json", FileMode.Open);
|
||||
FsExtractHashData expectedData = JsonSerializer.Deserialize<FsExtractHashData>(sr, serializerOptions);
|
||||
|
||||
Assert.NotNull(expectedData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user