diff --git a/BO4E/meta/LenientConverters/LenientSystemTextGeraetemerkmalGasConverter.cs b/BO4E/meta/LenientConverters/LenientSystemTextGeraetemerkmalGasConverter.cs index 551312fa..6ddc5ced 100644 --- a/BO4E/meta/LenientConverters/LenientSystemTextGeraetemerkmalGasConverter.cs +++ b/BO4E/meta/LenientConverters/LenientSystemTextGeraetemerkmalGasConverter.cs @@ -62,13 +62,6 @@ JsonSerializerOptions options ) { var stringValue = value.ToString(); - var match = GasPrefixRegex.Match(stringValue); - if (!match.Success) - { - writer.WriteStringValue(stringValue); - return; - } - var rest = match.Groups["rest"].Value; - writer.WriteStringValue(rest); + writer.WriteStringValue(stringValue); } } diff --git a/BO4ETestProject/TestGeraetemerkmalConverter.cs b/BO4ETestProject/TestGeraetemerkmalConverter.cs index 4862ce6a..7627d9ae 100644 --- a/BO4ETestProject/TestGeraetemerkmalConverter.cs +++ b/BO4ETestProject/TestGeraetemerkmalConverter.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Text.Json.Serialization; using BO4E.ENUM; using BO4E.meta.LenientConverters; @@ -85,6 +86,27 @@ public void TestNewtonsoft_Success_Nullable() result.Merkmal.Should().Be(Geraetemerkmal.GAS_G4); } + [TestMethod] + public void TestNewtonsoft_Success_Nullable_Serialization() + { + var myInstance = new SomethingWithANullableGeraetemerkmal() + { + Merkmal = Geraetemerkmal.GAS_G4, + }; + var result = JsonConvert.SerializeObject( + myInstance, + new JsonSerializerSettings() + { + Converters = new List() + { + new Newtonsoft.Json.Converters.StringEnumConverter(), + new LenientGeraetemerkmalGasConverter(), + }, + } + ); + result.Should().NotBeNullOrWhiteSpace().And.Contain("\"GAS_G4\"").And.NotContain("\"G4\""); + } + [TestMethod] public void TestNewtonsoft_Success_Nullable_WASSER_MWZW() { @@ -121,6 +143,21 @@ public void TestSystemText_Success_NonNullable() result.Merkmal.Should().Be(Geraetemerkmal.GAS_G4); } + [TestMethod] + public void TestSystemText_Success_NonNullable_Serialization() + { + var myInstance = new SomethingWithANullableGeraetemerkmal() + { + Merkmal = Geraetemerkmal.GAS_G4, + }; + var settings = new System.Text.Json.JsonSerializerOptions() + { + Converters = { new LenientSystemTextGeraetemerkmalGasConverter() }, + }; + var result = System.Text.Json.JsonSerializer.Serialize(myInstance, settings); + result.Should().NotBeNullOrWhiteSpace().And.Contain("\"GAS_G4\"").And.NotContain("\"G4\""); + } + [TestMethod] public void TestSystemText_Success_NonNullable_WASSER_MWZW() { @@ -213,7 +250,7 @@ public void TestSystemText_Write_NonNullable() }; var instance = new SomethingWithAGeraetemerkmal { Merkmal = Geraetemerkmal.GAS_G4 }; var json = System.Text.Json.JsonSerializer.Serialize(instance, settings); - json.Should().Be("{\"merkmal\":\"G4\"}"); + json.Should().Be($"{{\"merkmal\":\"{Geraetemerkmal.GAS_G4.ToString()}\"}}"); } [TestMethod]