Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Json Serialization #6152

Merged
merged 134 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 132 commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
9b184f2
System.Text.Json.Serialization
benaadams Mar 17, 2023
41c1b77
System.Text.Deserialization
benaadams Mar 21, 2023
dcbc874
Fixes
benaadams Apr 21, 2023
96ebbd1
lint
benaadams Apr 21, 2023
c67977f
Fixes
benaadams Apr 21, 2023
0c11085
Fix
benaadams Apr 21, 2023
157e4ab
Fixes
benaadams Apr 22, 2023
ab92141
Fixes
benaadams Apr 24, 2023
d037370
Lint
benaadams Apr 24, 2023
72c3d67
Fix invalid Json
benaadams Apr 24, 2023
b17a023
u8
benaadams Apr 24, 2023
c00cd5e
Fixes
benaadams Apr 24, 2023
a5a64c3
Fixes
benaadams Apr 25, 2023
f43e7bf
Fix
benaadams Apr 25, 2023
e9d5a6c
Don't go via exception for short reverts
benaadams Apr 25, 2023
ef3d3eb
Fix
benaadams Apr 25, 2023
59a3ae1
Fix
benaadams Apr 26, 2023
e88daf6
Multi-doc batch
benaadams Apr 27, 2023
1a439d9
Lint
benaadams Apr 27, 2023
6936a25
Merge conflict
benaadams Apr 27, 2023
d9ba033
Fixes
benaadams Apr 27, 2023
e4c026c
Lint
benaadams Apr 27, 2023
5799e2a
Fix tests
benaadams Apr 29, 2023
1536c35
Fix test
benaadams Apr 29, 2023
f0f751f
Tidy up
benaadams Apr 29, 2023
ecb2e4e
Turn of sync IO
benaadams Apr 30, 2023
be3a342
Async
benaadams Apr 30, 2023
34a1d54
Don't double Advance
benaadams Apr 30, 2023
c6c8fec
Async wrapper stream use
benaadams Apr 30, 2023
5514cac
Merge branch 'master' into Json-Deserialization
benaadams May 1, 2023
91e07d6
Merge branch 'master' into Json-Deserialization
benaadams May 9, 2023
28a344f
Fix build break
benaadams May 9, 2023
322ef7f
Merge branch 'master' into Json-Deserialization
benaadams Jun 14, 2023
8ab6ec9
Merge issues
benaadams Jun 14, 2023
ba4d771
Merge branch 'master' into Json-Deserialization
benaadams Jun 20, 2023
49000dd
Compile issues
benaadams Jun 20, 2023
444a605
File scoped namespaces
benaadams Sep 29, 2023
9078121
Merge branch 'master' into Json-Merged
benaadams Sep 29, 2023
5cbdd84
Formatting
benaadams Sep 29, 2023
016ae55
Merge fixes
benaadams Oct 2, 2023
0470632
Test Merge fixes
benaadams Oct 2, 2023
ab578a7
lang ver
benaadams Oct 2, 2023
f89ca26
Purge Newtonsoft
benaadams Oct 2, 2023
b5d5cea
Merge branch 'master' into Json-Merged
benaadams Oct 9, 2023
c834f64
Fix evm tests
benaadams Oct 9, 2023
cdaf00f
Fix parentBeaconBlockRootString serialization
benaadams Oct 12, 2023
6de4957
Change type for serialization
benaadams Oct 12, 2023
4670199
Merge branch 'master' into Json-Merged
benaadams Oct 16, 2023
c1b14d1
Ignore syncing
benaadams Oct 16, 2023
96a54f2
Capitalised bools are invalid json
benaadams Oct 16, 2023
bb997a3
Capitalised bools are invalid json
benaadams Oct 16, 2023
b4c847b
Merge branch 'master' into Json-Merged
benaadams Oct 23, 2023
cac495a
Fix merge conflict
benaadams Oct 23, 2023
c2b5fb2
Merge branch 'master' into Json-Merged
benaadams Oct 24, 2023
fa7eeb0
Fix data serialization
benaadams Oct 24, 2023
064f0d6
Fix trace entry
benaadams Oct 24, 2023
b300aae
Merge branch 'master' into Json-Merged
benaadams Oct 27, 2023
b5ffa8a
Merge conflicts
benaadams Oct 27, 2023
4c5505e
Formatting
benaadams Oct 27, 2023
10c780e
Merge branch 'master' into Json-Merged
benaadams Nov 9, 2023
c69dcbc
Missed merge
benaadams Nov 9, 2023
28deb3b
whitespace
benaadams Nov 9, 2023
c95919e
Fix EthereumTests Json
benaadams Nov 21, 2023
2e09edf
Ethereum tests
benaadams Nov 21, 2023
e62e14a
Fix hex prefix
benaadams Nov 21, 2023
1621eab
Fix difficultly test
benaadams Nov 21, 2023
7fe0186
Add serializer options
benaadams Nov 21, 2023
c8cc92a
Fix abi tests
benaadams Nov 21, 2023
dd45f0a
Merge branch 'master' into Json-Merged
benaadams Nov 21, 2023
25cb9de
Merge branch 'master' into Json-Merged
benaadams Nov 28, 2023
3880d35
Merge conflict
benaadams Nov 28, 2023
3216dbe
Merge branch 'master' into Json-Merged
benaadams Nov 28, 2023
2785a26
Feedback
benaadams Nov 28, 2023
ca38c66
revert to previous
benaadams Nov 28, 2023
3becbb2
Remove Netwonsoft
benaadams Nov 29, 2023
41b50a5
Merge branch 'master' into Json-Merged
benaadams Nov 29, 2023
05cf2f9
cosmetics
LukaszRozmej Dec 1, 2023
b81fb25
Pipeline Json responses
benaadams Dec 3, 2023
5fc41a5
Merge branch 'master' into Json-Merged
benaadams Dec 4, 2023
667e3e1
Merge fixes
benaadams Dec 4, 2023
b8988eb
Whitespace
benaadams Dec 4, 2023
a816ce3
fix test
benaadams Dec 4, 2023
e4625b8
Send multiple messages
benaadams Dec 4, 2023
db9e6a1
Optional stream closing
benaadams Dec 5, 2023
d8bc010
Merge branch 'master' into Json-Merged
benaadams Dec 5, 2023
cf7ac28
Case insensitive
benaadams Dec 5, 2023
a32aaa8
Merge branch 'master' into Json-Merged
benaadams Dec 5, 2023
b03c94f
Merge branch 'master' into Json-Merged
benaadams Dec 6, 2023
9087fb5
Update Nethermind.Serialization.Json.csproj
benaadams Dec 6, 2023
c0fd0b2
Whitespace
benaadams Dec 6, 2023
32de4ed
Update JavaScriptObjectConverter.cs
benaadams Dec 7, 2023
86b7d5f
Merge branch 'master' into Json-Merged
benaadams Dec 7, 2023
ad6062a
Feedback
benaadams Dec 7, 2023
a13c07b
Undo AI
benaadams Dec 7, 2023
730f59a
Put orders back
benaadams Dec 7, 2023
7414d13
Feedback
benaadams Dec 8, 2023
38faf4c
Whitespace
benaadams Dec 8, 2023
5510924
Use static constructor
benaadams Dec 8, 2023
280778b
Remove irrelevant test parameter
benaadams Dec 8, 2023
732490d
Add BigIntegerConverterTests back
benaadams Dec 8, 2023
edbc5a5
Use FrozenDictionary
benaadams Dec 8, 2023
6b4ae92
Deserialize collection to ArrayPoolList using GetArrayLength for init…
LukaszRozmej Dec 8, 2023
bb5fa60
simplify
LukaszRozmej Dec 8, 2023
51555be
Throw more explicit exception
benaadams Dec 8, 2023
3bf3684
name cleanup
LukaszRozmej Dec 8, 2023
f9feba9
Merge branch 'master' into Json-Merged
benaadams Dec 8, 2023
2dcce2e
Merge conflicts
benaadams Dec 8, 2023
4179ee4
Merge conflict
benaadams Dec 8, 2023
2adf079
Add comments
benaadams Dec 8, 2023
7cdd14c
more comments
LukaszRozmej Dec 8, 2023
4c61397
Consolidate Disposable
benaadams Dec 8, 2023
d27a21e
Use FrozenDictionary for RpcLookup
benaadams Dec 8, 2023
f2ca3a0
Case sensitive
benaadams Dec 8, 2023
3c9d55d
Be consistent on parsing type
benaadams Dec 9, 2023
e301922
Use correct type in test
benaadams Dec 9, 2023
fc2425d
Optimizations
benaadams Dec 9, 2023
8256cb0
Optimizations
benaadams Dec 9, 2023
cff1832
Optimize
benaadams Dec 9, 2023
20b3e91
Optimize
benaadams Dec 9, 2023
30b4d68
Vectorize FromUtf8 hex
benaadams Dec 9, 2023
ba5c114
Optimization
benaadams Dec 9, 2023
74f5062
Optimize
benaadams Dec 10, 2023
94b08e3
Parallel deserialize
benaadams Dec 10, 2023
ac2cc64
Revert "Parallel deserialize"
benaadams Dec 10, 2023
59069e1
Use using
benaadams Dec 10, 2023
b7aa46e
Fix check
benaadams Dec 10, 2023
ef109b0
Parallel deserialize
benaadams Dec 10, 2023
94642d1
Increase parallelThreshold
benaadams Dec 10, 2023
fcca2bc
Use correct length
benaadams Dec 10, 2023
0838b3a
Cache Reflection Parameters
benaadams Dec 10, 2023
55fcf10
Fix tracing output
benaadams Dec 11, 2023
db4cced
Match geth output
benaadams Dec 11, 2023
2cd34ac
Turn AllowSynchronousIO back on
benaadams Dec 11, 2023
d498700
Revert object type arrays
benaadams Dec 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Nethermind/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<PackageVersion Include="Nethermind.DotNetty.Transport" Version="1.0.1" />
<PackageVersion Include="Nethermind.Gmp" Version="1.0.1" />
<PackageVersion Include="Nethermind.Numerics.Int256" Version="1.1.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Nito.Collections.Deque" Version="1.2.1" />
<PackageVersion Include="NLog" Version="5.2.7" />
<PackageVersion Include="NLog.Targets.Seq" Version="3.0.0" />
Expand All @@ -79,6 +78,7 @@
<PackageVersion Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageVersion Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Runtime.Caching" Version="8.0.0" />
Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Ethereum.Abi.Test/AbiTest.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Ethereum.Abi.Test
{
public class AbiTest
{
[JsonProperty(PropertyName = "args")]
[JsonPropertyName("args")]
public object[] Args { get; set; }

[JsonProperty(PropertyName = "result")]
[JsonPropertyName("result")]
public string Result { get; set; }

[JsonProperty(PropertyName = "types")]
[JsonPropertyName("types")]
public string[] Types { get; set; }
}
}
11 changes: 6 additions & 5 deletions src/Nethermind/Ethereum.Abi.Test/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;

using FluentAssertions;
using Nethermind.Abi;
using Nethermind.Core.Extensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;

namespace Ethereum.Abi.Test
Expand Down Expand Up @@ -56,7 +57,7 @@ public void Test_abi_encoding()
}
}

Dictionary<string, AbiTest> tests = JsonConvert.DeserializeObject<Dictionary<string, AbiTest>>(text);
Dictionary<string, AbiTest> tests = JsonSerializer.Deserialize<Dictionary<string, AbiTest>>(text);
foreach ((string testName, AbiTest abiTest) in tests)
{
AbiSignature signature = new(
Expand All @@ -71,9 +72,9 @@ public void Test_abi_encoding()

public object JsonToObject(object jsonObject)
{
if (jsonObject is JArray array)
if (jsonObject is JsonArray array)
{
return array.Select(t => t.Value<long>()).ToArray();
return array.Select(t => t.GetValue<long>()).ToArray();
}

return jsonObject;
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Ethereum.Basic.Test/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text.Json.Serialization;

using Ethereum.Test.Base;
using Nethermind.Core;
using Nethermind.Core.Extensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit.Analyzers">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NUnit3TestAdapter" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TransactionJsonTest : GeneralStateTestBase
public void Can_load_access_lists()
{
const string lists =
"{\"accessLists\": [[{address: \"0x0001020304050607080900010203040506070809\", storageKeys: [\"0x00\", \"0x01\"]}]]}";
"{\"accessLists\": [[{\"address\": \"0x0001020304050607080900010203040506070809\", \"storageKeys\": [\"0x00\", \"0x01\"]}]]}";

EthereumJsonSerializer serializer = new EthereumJsonSerializer();
TransactionJson txJson = serializer.Deserialize<TransactionJson>(lists);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Text.Json.Serialization;

namespace Ethereum.Difficulty.Test
{
public class DifficultyTestHexJson
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Ethereum.Difficulty.Test/DifficultyTestJson.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Text.Json.Serialization;

namespace Ethereum.Difficulty.Test
{
public class DifficultyTestJson
Expand Down
7 changes: 5 additions & 2 deletions src/Nethermind/Ethereum.HexPrefix.Test/HexPrefixTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

using Ethereum.Test.Base;
using Nethermind.Core.Extensions;

using NUnit.Framework;

namespace Ethereum.HexPrefix.Test
Expand All @@ -18,7 +21,7 @@ public static IEnumerable<HexPrefixTest> LoadTests()
{
return TestLoader.LoadFromFile<Dictionary<string, HexPrefixTestJson>, HexPrefixTest>(
"hexencodetest.json",
c => c.Select(p => new HexPrefixTest(p.Key, p.Value.Seq, p.Value.Term, p.Value.Out)));
c => c.Select(p => new HexPrefixTest(p.Key, p.Value.Seq.Select(x => (byte)x).ToArray(), p.Value.Term, p.Value.Out)));
}

[TestCaseSource(nameof(LoadTests))]
Expand All @@ -36,7 +39,7 @@ public void Test(HexPrefixTest test)

private class HexPrefixTestJson
{
public byte[] Seq { get; set; }
public int[] Seq { get; set; }
benaadams marked this conversation as resolved.
Show resolved Hide resolved
public bool Term { get; set; }
public string Out { get; set; }
}
Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Ethereum.KeyAddress.Test/KeyAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json.Serialization;

using Ethereum.Test.Base;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Crypto;
using Nethermind.Int256;
using Nethermind.Logging;
using Newtonsoft.Json;
using NUnit.Framework;

namespace Ethereum.KeyAddress.Test
Expand Down Expand Up @@ -96,7 +97,7 @@ private class SigOfEmptyString

private class KeyAddressTestJson
{
[JsonProperty("sig_of_emptystring")]
[JsonPropertyName("sig_of_emptystring")]
public SigOfEmptyString Signature { get; set; }

public string Seed { get; set; }
Expand Down
6 changes: 4 additions & 2 deletions src/Nethermind/Ethereum.KeyStore.Test/KeyStoreJsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.IO;
using System.Security;
using System.Text.Json.Serialization;

using Nethermind.Core;
using Nethermind.Core.Collections;
using Nethermind.Crypto;
Expand All @@ -12,7 +14,7 @@
using Nethermind.KeyStore.Config;
using Nethermind.Logging;
using Nethermind.Serialization.Json;
using Newtonsoft.Json;

using NUnit.Framework;

namespace Ethereum.KeyStore.Test
Expand Down Expand Up @@ -129,7 +131,7 @@ private class KeyStoreTestsModel

private class KeyStoreTestModel
{
[JsonProperty(PropertyName = "Json")]
[JsonPropertyName("Json")]
public KeyStoreItem KeyData { get; set; }
public string Password { get; set; }
public string Priv { get; set; }
Expand Down
11 changes: 6 additions & 5 deletions src/Nethermind/Ethereum.PoW.Test/EthashTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text.Json.Serialization;

using Ethereum.Test.Base;
using Nethermind.Consensus.Ethash;
using Nethermind.Core;
Expand All @@ -15,7 +17,6 @@
using Nethermind.Crypto;
using Nethermind.Logging;
using Nethermind.Serialization.Rlp;
using Newtonsoft.Json;
using NUnit.Framework;

namespace Ethereum.PoW.Test
Expand Down Expand Up @@ -103,16 +104,16 @@ private class EthashTestJson
public string Header { get; set; }
public string Seed { get; set; }

[JsonProperty("cache_size")]
[JsonPropertyName("cache_size")]
public int CacheSize { get; set; }

[JsonProperty("full_size")]
[JsonPropertyName("full_size")]
public int FullSize { get; set; }

[JsonProperty("header_hash")]
[JsonPropertyName("header_hash")]
public string HeaderHash { get; set; }

[JsonProperty("cache_hash")]
[JsonPropertyName("cache_hash")]
public string CacheHash { get; set; }

public string Result { get; set; }
Expand Down
3 changes: 0 additions & 3 deletions src/Nethermind/Ethereum.Test.Base/AccessListJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Newtonsoft.Json;

namespace Ethereum.Test.Base
{
public class AccessListItemJson
{
[JsonProperty("address")]
public Address Address { get; set; }

[JsonProperty("storageKeys")]
public byte[][] StorageKeys { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/Nethermind/Ethereum.Test.Base/EthereumTestResult.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Text.Json.Serialization;

using Nethermind.Core.Crypto;
using Newtonsoft.Json;

namespace Ethereum.Test.Base
{
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/GeneralStateTestJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Ethereum.Test.Base
{
public class GeneralStateTestJson
{
[JsonProperty("_info")]
[JsonPropertyName("_info")]
public GeneralStateTestInfoJson? Info { get; set; }
public GeneralStateTestEnvJson? Env { get; set; }
public Dictionary<string, PostStateJson[]>? Post { get; set; }
Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/TestBlockJson.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Newtonsoft.Json;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Ethereum.Test.Base
{
Expand All @@ -11,7 +12,7 @@ public class TestBlockJson
public TestBlockHeaderJson[]? UncleHeaders { get; set; }
public string? Rlp { get; set; }
public LegacyTransactionJson[]? Transactions { get; set; }
[JsonProperty("expectException")]
[JsonPropertyName("expectException")]
public string? ExpectedException { get; set; }
}
}
46 changes: 29 additions & 17 deletions src/Nethermind/Ethereum.Test.Base/TestLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;

using NUnit.Framework;

namespace Ethereum.Test.Base
Expand All @@ -17,30 +19,33 @@ public static class TestLoader
{
public static object PrepareInput(object input)
{
string s = input as string;
if (s != null && s.StartsWith("#"))
if (input is string s && s.StartsWith("#"))
{
BigInteger bigInteger = BigInteger.Parse(s.Substring(1));
input = bigInteger;
}

if (input is JArray)
{
input = ((JArray)input).Select(PrepareInput).ToArray();
}
JsonElement token = (JsonElement)input;

JToken token = input as JToken;
if (token != null)
if (token.ValueKind == JsonValueKind.Array)
{
if (token.Type == JTokenType.String)
object[] array = new object[token.GetArrayLength()];
for (int i = 0; i < array.Length; i++)
{
return token.Value<string>();
array[i] = PrepareInput(token[i]);
}

if (token.Type == JTokenType.Integer)
{
return token.Value<long>();
}
input = array;
}

if (token.ValueKind == JsonValueKind.String)
{
return token.GetString()!;
}

if (token.ValueKind == JsonValueKind.Number)
{
return token.GetInt64();
}

return input;
Expand All @@ -58,14 +63,21 @@ public static IEnumerable<TTest> LoadFromFile<TContainer, TTest>(
throw new ArgumentException($"Cannot find test resource: {testFileName}");
}

var jsonOptions = new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
NumberHandling = JsonNumberHandling.AllowReadingFromString
};
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
Assert.NotNull(stream);
using (StreamReader reader = new(stream))
{
string testJson = reader.ReadToEnd();
TContainer testSpecs =
JsonConvert.DeserializeObject<TContainer>(testJson);
JsonSerializer.Deserialize<TContainer>(testJson, jsonOptions);
return testExtractor(testSpecs);
}
}
Expand Down
Loading