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: Support Deserializing Geraetemerkmal "G2.5", not only "G2Period5" #584

Merged
merged 2 commits into from
Nov 14, 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 @@ -48,11 +48,14 @@ JsonSerializer serializer
}
catch (ArgumentException) when (rawValue.StartsWith("G"))
{
if (rawValue == "G2Period5")
switch (rawValue)
{
return Geraetemerkmal.GAS_G2P5;
case "G2Period5":
case "G2.5":
return Geraetemerkmal.GAS_G2P5;
default:
return Enums.Parse<Geraetemerkmal>("GAS_" + rawValue);
}
return Enums.Parse<Geraetemerkmal>("GAS_" + rawValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ JsonSerializerOptions options
}
catch (ArgumentException) when (rawString.StartsWith("G"))
{
if (rawString == "G2Period5")
switch (rawString)
{
return Geraetemerkmal.GAS_G2P5;
case "G2Period5":
case "G2.5":
return Geraetemerkmal.GAS_G2P5;
default:
return Enums.Parse<Geraetemerkmal>("GAS_" + rawString);
}
return Enums.Parse<Geraetemerkmal>("GAS_" + rawString);
}
}

Expand Down
41 changes: 41 additions & 0 deletions BO4ETestProject/TestGeraetemerkmalConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TestGeraeteerkmalDeserialization
{
private const string JsonString = "{\"merkmal\":\"G4\"}";
private const string JsonStringWithPeriod = "{\"merkmal\":\"G2Period5\"}";
private const string JsonStringWithLiteralFullstop = "{\"merkmal\":\"G2.5\"}";
private const string JsonStringWasser = "{\"merkmal\":\"WASSER_MWZW\"}";

internal class SomethingWithAGeraetemerkmal
Expand Down Expand Up @@ -163,6 +164,46 @@ public void TestSystemText_Nullable_Success_GPointSomething()
result.Merkmal.Should().Be(Geraetemerkmal.GAS_G2P5);
}

[TestMethod]
public void TestNewtonsoft_Success_Nullable_With_Literal_Fullstop()
{
var result =
Newtonsoft.Json.JsonConvert.DeserializeObject<SomethingWithANullableGeraetemerkmal>(
JsonStringWithLiteralFullstop,
new LenientGeraetemerkmalGasConverter()
);
result.Merkmal.Should().Be(Geraetemerkmal.GAS_G2P5);
}

[TestMethod]
public void TestSystemText_Success_With_Literal_Fullstop()
{
var settings = new System.Text.Json.JsonSerializerOptions()
{
Converters = { new LenientSystemTextGeraetemerkmalGasConverter() },
};
var result = System.Text.Json.JsonSerializer.Deserialize<SomethingWithAGeraetemerkmal>(
JsonStringWithLiteralFullstop,
settings
);
result.Merkmal.Should().Be(Geraetemerkmal.GAS_G2P5);
}

[TestMethod]
public void TestSystemText_Success_With_Nullable_Literal_Fullstop()
{
var settings = new System.Text.Json.JsonSerializerOptions()
{
Converters = { new LenientSystemTextGeraetemerkmalGasConverter() },
};
var result =
System.Text.Json.JsonSerializer.Deserialize<SomethingWithANullableGeraetemerkmal>(
JsonStringWithLiteralFullstop,
settings
);
result.Merkmal.Should().Be(Geraetemerkmal.GAS_G2P5);
}

[TestMethod]
public void TestSystemText_Write_NonNullable()
{
Expand Down
Loading