From 023724eb5d32f936ff12c0f1d4b6636df3c2a6a7 Mon Sep 17 00:00:00 2001 From: Mithilesh Zavar Date: Sat, 22 Mar 2025 14:53:39 +0000 Subject: [PATCH 1/2] Change the `long-full` template for Read() to convert to Int64 --- src/StronglyTypedIds.Templates/long-full.typedid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StronglyTypedIds.Templates/long-full.typedid b/src/StronglyTypedIds.Templates/long-full.typedid index c63c34af9..924b02ce5 100644 --- a/src/StronglyTypedIds.Templates/long-full.typedid +++ b/src/StronglyTypedIds.Templates/long-full.typedid @@ -88,7 +88,7 @@ public partial class PLACEHOLDERIDSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter { public override PLACEHOLDERID Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) - => new (reader.GetInt32()); + => new (reader.GetInt64()); public override void Write(global::System.Text.Json.Utf8JsonWriter writer, PLACEHOLDERID value, global::System.Text.Json.JsonSerializerOptions options) => writer.WriteNumberValue(value.Value); From ac0614e04cf4f782b27b66b9f42f506c472d820c Mon Sep 17 00:00:00 2001 From: Mithilesh Zavar Date: Sat, 22 Mar 2025 15:13:56 +0000 Subject: [PATCH 2/2] Add unit test for maximum `long` value --- .../StronglyTypedIds.IntegrationTests/LongIdTests.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/StronglyTypedIds.IntegrationTests/LongIdTests.cs b/test/StronglyTypedIds.IntegrationTests/LongIdTests.cs index 45805b944..6f541b6d7 100644 --- a/test/StronglyTypedIds.IntegrationTests/LongIdTests.cs +++ b/test/StronglyTypedIds.IntegrationTests/LongIdTests.cs @@ -258,6 +258,18 @@ public void CanDeserializeFromLong_WithSystemTextJsonProvider() Assert.Equal(foo, deserializedFoo); } + [Fact] + public void CanDeserializeFromLong_MaxLongValue_WithSystemTextJsonProvider() + { + var value = long.MaxValue; + var foo = new ConvertersLongId(value); + var serializedLong = SystemTextJsonSerializer.Serialize(value); + + var deserializedFoo = SystemTextJsonSerializer.Deserialize(serializedLong); + + Assert.Equal(foo, deserializedFoo); + } + [Fact] public void WhenEfCoreValueConverterUsesValueConverter() {