Skip to content

Commit 2d4c52d

Browse files
authored
[DX-388] Fix BigIntegerJsonConverters (#14)
1 parent 2107077 commit 2d4c52d

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/Enjin.Platform.Sdk/Enjin.Platform.Sdk.Tests/Unit/Json/BigIntegerJsonConverterTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public void DeserializeWhenGivenValidJsonStringReturnsExpected(string json)
3737

3838
[Test]
3939
[TestCase(@"null")]
40-
[TestCase(@"0")]
4140
[TestCase(@"""1.1579E+77""")]
4241
[TestCase(@"""1.0""")]
4342
[TestCase(@"[]")]

src/Enjin.Platform.Sdk/Enjin.Platform.Sdk.Tests/Unit/Json/NullableBigIntegerJsonConverterTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public void DeserializeWhenGivenNullJsonValueReturnsNull()
5353
}
5454

5555
[Test]
56-
[TestCase(@"0")]
5756
[TestCase(@"""1.1579E+77""")]
5857
[TestCase(@"""1.0""")]
5958
[TestCase(@"[]")]

src/Enjin.Platform.Sdk/Enjin.Platform.Sdk/Json/BigIntegerJsonConverter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ public class BigIntegerJsonConverter : JsonConverter<BigInteger>
2323
/// <inheritdoc/>
2424
/// </para>
2525
/// <para>
26-
/// When returned in a response, the <c>BigInt</c> type on the platform is expected to be returned as a string and
27-
/// as such this converter only expects string.
26+
/// When returned in a response, the <c>BigInt</c> type on the platform is expected to be returned as an int or a
27+
/// string and as such this converter only expects number or string types.
2828
/// </para>
2929
/// </remarks>
3030
public override BigInteger Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3131
{
3232
return reader.TokenType switch
3333
{
34+
JsonTokenType.Number => new BigInteger(reader.GetInt32()),
3435
JsonTokenType.String => BigInteger.Parse(reader.GetString()!, NumberStyles.Integer),
3536
_ => throw new FormatException($"Invalid {nameof(JsonTokenType)} for {nameof(BigInteger)} field")
3637
};

src/Enjin.Platform.Sdk/Enjin.Platform.Sdk/Json/NullableBigIntegerJsonConverter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ public class NullableBigIntegerJsonConverter : JsonConverter<BigInteger?>
2424
/// <inheritdoc/>
2525
/// </para>
2626
/// <para>
27-
/// When returned in a response, the <c>BigInt</c> type on the platform is expected to be returned as a string and
28-
/// as such this converter only expects string or null JSON types.
27+
/// When returned in a response, the <c>BigInt</c> type on the platform is expected to be returned as an int or a
28+
/// string and as such this converter only expects number, string or null JSON types.
2929
/// </para>
3030
/// </remarks>
3131
public override BigInteger? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3232
{
3333
return reader.TokenType switch
3434
{
35+
JsonTokenType.Number => new BigInteger(reader.GetInt32()),
3536
JsonTokenType.String => BigInteger.Parse(reader.GetString()!, NumberStyles.Integer),
3637
JsonTokenType.Null => null,
3738
_ => throw new FormatException($"Invalid {nameof(JsonTokenType)} for {nameof(Nullable<BigInteger>)} field")

0 commit comments

Comments
 (0)