Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, Int128 val
{
Span<byte> buffer = stackalloc byte[MaxFormatLength];
Format(buffer, value, out int written);
writer.WritePropertyName(buffer);
writer.WritePropertyName(buffer.Slice(0, written));
}

internal override Int128 ReadNumberWithCustomHandling(ref Utf8JsonReader reader, JsonNumberHandling handling, JsonSerializerOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, UInt128 va
{
Span<byte> buffer = stackalloc byte[MaxFormatLength];
Format(buffer, value, out int written);
writer.WritePropertyName(buffer);
writer.WritePropertyName(buffer.Slice(0, written));
}

internal override UInt128 ReadNumberWithCustomHandling(ref Utf8JsonReader reader, JsonNumberHandling handling, JsonSerializerOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,44 @@ public static void TimeOnly_Write_Success(string value, string? expectedValue =
string json = JsonSerializer.Serialize(ts);
Assert.Equal($"\"{expectedValue ?? value}\"", json);
}

[Fact]
public static void Int128_AsDictionaryKey_SerializesCorrectly()
{
// Regression test for https://github.com/dotnet/runtime/issues/116855
var dict = new Dictionary<Int128, string>
{
[0] = "Zero",
[1] = "One",
[-1] = "MinusOne",
[Int128.MaxValue] = "Max",
[Int128.MinValue] = "Min"
};

string json = JsonSerializer.Serialize(dict);
Assert.Equal("""{"0":"Zero","1":"One","-1":"MinusOne","170141183460469231731687303715884105727":"Max","-170141183460469231731687303715884105728":"Min"}""", json);

var deserialized = JsonSerializer.Deserialize<Dictionary<Int128, string>>(json);
Assert.Equal(dict, deserialized);
}

[Fact]
public static void UInt128_AsDictionaryKey_SerializesCorrectly()
{
// Regression test for https://github.com/dotnet/runtime/issues/116855
var dict = new Dictionary<UInt128, string>
{
[0] = "Zero",
[1] = "One",
[UInt128.MaxValue] = "Max"
};

string json = JsonSerializer.Serialize(dict);
Assert.Equal("""{"0":"Zero","1":"One","340282366920938463463374607431768211455":"Max"}""", json);

var deserialized = JsonSerializer.Deserialize<Dictionary<UInt128, string>>(json);
Assert.Equal(dict, deserialized);
}
#endif
}
}
Loading