From 82ea7d35f57ebf9d4d672a87cb94f75c5596c355 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 31 Oct 2024 12:57:18 +0100 Subject: [PATCH 1/5] feat: Annotate `COM.Verwendungszweck.Zwecke` with new JsonConverters introduced and tested in https://github.com/Hochfrequenz/BO4E-dotnet/pull/565 --- BO4E/COM/Zaehlwerk.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BO4E/COM/Zaehlwerk.cs b/BO4E/COM/Zaehlwerk.cs index 3dd796f2..3f085fe0 100644 --- a/BO4E/COM/Zaehlwerk.cs +++ b/BO4E/COM/Zaehlwerk.cs @@ -3,6 +3,7 @@ using System.Text.Json.Serialization; using BO4E.ENUM; using BO4E.meta; +using BO4E.meta.LenientConverters; using Newtonsoft.Json; using ProtoBuf; @@ -87,6 +88,8 @@ public class Zaehlwerk : COM [NonOfficial(NonOfficialCategory.CUSTOMER_REQUIREMENTS)] [ProtoMember(1011)] [JsonPropertyOrder(1011)] + [System.Text.Json.Serialization.JsonConverter(typeof(SystemTextVerwendungszweckEnumToComConverter))] + [Newtonsoft.Json.JsonConverter(typeof(NewtonsoftVerwendungszweckEnumToComConverter))] public List? Verwendungszwecke { get; set; } /// Stromverbrauchsart/Verbrauchsart Marktlokation From f8fc590930c16b37f892469c538bb233f885d24f Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 31 Oct 2024 12:59:17 +0100 Subject: [PATCH 2/5] this one --- BO4E/COM/Verwendungszweck.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BO4E/COM/Verwendungszweck.cs b/BO4E/COM/Verwendungszweck.cs index 3c3694e9..3932a581 100644 --- a/BO4E/COM/Verwendungszweck.cs +++ b/BO4E/COM/Verwendungszweck.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Text.Json.Serialization; using BO4E.meta; +using BO4E.meta.LenientConverters; using Newtonsoft.Json; using ProtoBuf; @@ -27,5 +28,7 @@ public class Verwendungszweck : COM [JsonProperty(PropertyName = "zweck")] [JsonPropertyName("zweck")] [ProtoMember(4)] + [System.Text.Json.Serialization.JsonConverter(typeof(SystemTextVerwendungszweckEnumToComConverter))] + [Newtonsoft.Json.JsonConverter(typeof(NewtonsoftVerwendungszweckEnumToComConverter))] public List? Zweck { get; set; } } From f97d664b04081ea6d70b08c755d9c94b3aa15a8e Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 31 Oct 2024 12:59:31 +0100 Subject: [PATCH 3/5] Revert "feat: Annotate `COM.Verwendungszweck.Zwecke` with new JsonConverters" This reverts commit 82ea7d35f57ebf9d4d672a87cb94f75c5596c355. --- BO4E/COM/Zaehlwerk.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/BO4E/COM/Zaehlwerk.cs b/BO4E/COM/Zaehlwerk.cs index 3f085fe0..3dd796f2 100644 --- a/BO4E/COM/Zaehlwerk.cs +++ b/BO4E/COM/Zaehlwerk.cs @@ -3,7 +3,6 @@ using System.Text.Json.Serialization; using BO4E.ENUM; using BO4E.meta; -using BO4E.meta.LenientConverters; using Newtonsoft.Json; using ProtoBuf; @@ -88,8 +87,6 @@ public class Zaehlwerk : COM [NonOfficial(NonOfficialCategory.CUSTOMER_REQUIREMENTS)] [ProtoMember(1011)] [JsonPropertyOrder(1011)] - [System.Text.Json.Serialization.JsonConverter(typeof(SystemTextVerwendungszweckEnumToComConverter))] - [Newtonsoft.Json.JsonConverter(typeof(NewtonsoftVerwendungszweckEnumToComConverter))] public List? Verwendungszwecke { get; set; } /// Stromverbrauchsart/Verbrauchsart Marktlokation From b90aa51585c5abd2936b9184899231836b17a7c7 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 31 Oct 2024 13:02:38 +0100 Subject: [PATCH 4/5] jetzt aber --- BO4E/COM/Verwendungszweck.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BO4E/COM/Verwendungszweck.cs b/BO4E/COM/Verwendungszweck.cs index 3932a581..f224dff5 100644 --- a/BO4E/COM/Verwendungszweck.cs +++ b/BO4E/COM/Verwendungszweck.cs @@ -12,6 +12,8 @@ namespace BO4E.COM; /// [ProtoContract] [NonOfficial(NonOfficialCategory.REGULATORY_REQUIREMENTS)] +[System.Text.Json.Serialization.JsonConverter(typeof(SystemTextVerwendungszweckEnumToComConverter))] +[Newtonsoft.Json.JsonConverter(typeof(NewtonsoftVerwendungszweckEnumToComConverter))] public class Verwendungszweck : COM { /// @@ -28,7 +30,5 @@ public class Verwendungszweck : COM [JsonProperty(PropertyName = "zweck")] [JsonPropertyName("zweck")] [ProtoMember(4)] - [System.Text.Json.Serialization.JsonConverter(typeof(SystemTextVerwendungszweckEnumToComConverter))] - [Newtonsoft.Json.JsonConverter(typeof(NewtonsoftVerwendungszweckEnumToComConverter))] public List? Zweck { get; set; } } From 604f376c47ff2cc75ff5c56ace58d9eef7434b4c Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 31 Oct 2024 13:10:27 +0100 Subject: [PATCH 5/5] add tests --- ...tJsonVerwendungszweckEnumToComConverter.cs | 12 +++---- BO4ETestProject/TestStringEnumConverter.cs | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/BO4E/meta/LenientConverters/SystemTextJsonVerwendungszweckEnumToComConverter.cs b/BO4E/meta/LenientConverters/SystemTextJsonVerwendungszweckEnumToComConverter.cs index 75bba3c1..3d364a52 100644 --- a/BO4E/meta/LenientConverters/SystemTextJsonVerwendungszweckEnumToComConverter.cs +++ b/BO4E/meta/LenientConverters/SystemTextJsonVerwendungszweckEnumToComConverter.cs @@ -26,15 +26,13 @@ JsonSerializerOptions options { return null; } - - var result = new Verwendungszweck - { - Marktrolle = ENUM.Marktrolle.LF, - Zweck = new List(), - }; - if (reader.TokenType == JsonTokenType.String) { + var result = new Verwendungszweck + { + Marktrolle = ENUM.Marktrolle.LF, + Zweck = new List(), + }; string stringValue = reader.GetString()!; // Adjust the string as per the Newtonsoft version diff --git a/BO4ETestProject/TestStringEnumConverter.cs b/BO4ETestProject/TestStringEnumConverter.cs index 28f7a620..11aa0066 100644 --- a/BO4ETestProject/TestStringEnumConverter.cs +++ b/BO4ETestProject/TestStringEnumConverter.cs @@ -763,4 +763,40 @@ string jsonString var reSerializedJsonString = System.Text.Json.JsonSerializer.Serialize(result); reSerializedJsonString.Should().Contain("MEHRMINDERMENGENABRECHNUNG"); } + + [TestMethod] + [DataRow("{\"verwendungszwecke\": [{\"zwecke\":\"MEHRMINDERMENGENABRECHNUNG\"}]")] + public void Test_STJ_VerwendungszweckEnum_To_COM_Converter_With_Annotated_Property_At_Zaehlwerk( + string jsonString + ) + { + var result = System.Text.Json.JsonSerializer.Deserialize(jsonString); + result + .Should() + .NotBeNull() + .And.Subject.As() + .Verwendungszwecke?.Should() + .NotBeNull() + .And.ContainEquivalentOf(BO4E.ENUM.Verwendungszweck.MEHRMINDERMENGENABRECHNUNG); + var reSerializedJsonString = System.Text.Json.JsonSerializer.Serialize(result); + reSerializedJsonString.Should().Contain("MEHRMINDERMENGENABRECHNUNG"); + } + + [TestMethod] + [DataRow("{\"verwendungszwecke\": [{\"zwecke\":\"MEHRMINDERMENGENABRECHNUNG\"}]")] + public void Test_Newtonsoft_VerwendungszweckEnum_To_COM_Converter_With_Annotated_Property_At_Zaehlwerk( + string jsonString + ) + { + var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString); + result + .Should() + .NotBeNull() + .And.Subject.As() + .Verwendungszwecke?.Should() + .NotBeNull() + .And.ContainEquivalentOf(BO4E.ENUM.Verwendungszweck.MEHRMINDERMENGENABRECHNUNG); + var reSerializedJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(result); + reSerializedJsonString.Should().Contain("MEHRMINDERMENGENABRECHNUNG"); + } }