Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Serialize Geraetemerkmal WITH GAS_ prefix in STJ (instead of w/o) #618

Merged
merged 2 commits into from
Dec 10, 2024
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 @@ -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);
}
}
39 changes: 38 additions & 1 deletion BO4ETestProject/TestGeraetemerkmalConverter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using BO4E.ENUM;
using BO4E.meta.LenientConverters;
Expand Down Expand Up @@ -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<Newtonsoft.Json.JsonConverter>()
{
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()
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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]
Expand Down
Loading