diff --git a/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs b/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs index 03c90626..84d9127a 100644 --- a/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs +++ b/src/fiskaltrust.Launcher.Common/Configuration/Configuration.cs @@ -197,12 +197,11 @@ public static LauncherConfiguration Deserialize(string text) var configuration = JsonSerializer.Deserialize( text, typeof(LauncherConfiguration), - new SerializerContext(new JsonSerializerOptions + new JsonSerializerOptions { - Converters = { - new JsonStringEnumConverter() - }, - }) + PropertyNameCaseInsensitive = true, + Converters = { new JsonStringEnumConverter() }, + } ) as LauncherConfiguration ?? throw new Exception($"Could not deserialize {nameof(LauncherConfiguration)}"); configuration.SetAlternateNames(text); return configuration; @@ -339,12 +338,11 @@ public record LauncherConfigurationInCashBoxConfiguration var configuration = (JsonSerializer.Deserialize( text, typeof(LauncherConfigurationInCashBoxConfiguration), - new SerializerContext(new JsonSerializerOptions + new JsonSerializerOptions { - Converters = { - new JsonStringEnumConverter() - } - }) + PropertyNameCaseInsensitive = true, + Converters = { new JsonStringEnumConverter() }, + } ) as LauncherConfigurationInCashBoxConfiguration ?? throw new Exception($"Could not deserialize {nameof(LauncherConfigurationInCashBoxConfiguration)}")).LauncherConfiguration; configuration?.SetAlternateNames(text); return configuration; diff --git a/test/fiskaltrust.Launcher.UnitTest/Configuration/Configuration.cs b/test/fiskaltrust.Launcher.UnitTest/Configuration/Configuration.cs index b6076319..c6875ab6 100644 --- a/test/fiskaltrust.Launcher.UnitTest/Configuration/Configuration.cs +++ b/test/fiskaltrust.Launcher.UnitTest/Configuration/Configuration.cs @@ -47,5 +47,55 @@ public void RandomConfiguration_SerializaAndDeserialize_ShouldPreserveNull() deserialized.Should().BeEquivalentTo(deserialized); } } + + [Fact] + public void DifferentCaseInKeys_Deserialize_ShouldPreserveProperties() + { + var json = @"{ + ""loglevel"": ""Information"", + ""LOGLEVEL"": ""Error"", + ""LogLevel"": ""Warning"" + }"; + + var deserialized = LauncherConfiguration.Deserialize(json); + + deserialized.LogLevel.Should().Be(LogLevel.Warning); + } + + [Fact] + public void LowerCaseKeys_Deserialize_ShouldPreserveProperties() + { + var json = @"{ + ""loglevel"": ""Information"" + }"; + + var deserialized = LauncherConfiguration.Deserialize(json); + + deserialized.LogLevel.Should().Be(LogLevel.Information); + } + + [Fact] + public void UpperCaseKeys_Deserialize_ShouldPreserveProperties() + { + var json = @"{ + ""LOGLEVEL"": ""Error"" + }"; + + var deserialized = LauncherConfiguration.Deserialize(json); + + deserialized.LogLevel.Should().Be(LogLevel.Error); + } + + [Fact] + public void MixedCaseKeys_Deserialize_ShouldPreserveProperties() + { + var json = @"{ + ""logLevel"": ""Warning"" + }"; + + var deserialized = LauncherConfiguration.Deserialize(json); + + deserialized.LogLevel.Should().Be(LogLevel.Warning); + } } } \ No newline at end of file