diff --git a/Core/Utils/Json/Converters/EftEnumConverter.cs b/Core/Utils/Json/Converters/EftEnumConverter.cs index fc19663c..9e1016c8 100644 --- a/Core/Utils/Json/Converters/EftEnumConverter.cs +++ b/Core/Utils/Json/Converters/EftEnumConverter.cs @@ -47,6 +47,20 @@ public class EftEnumConverter : JsonConverter public override void WriteAsPropertyName(Utf8JsonWriter writer, [DisallowNull] T value, JsonSerializerOptions options) { - writer.WritePropertyName(value.ToString()); + object propertyValue = null; + if (typeof(T).GetFields().Any(f => f.FieldType == typeof(string))) + { + propertyValue = value as string; + } + else + { + if (typeof(T).GetFields().Any(f => f.FieldType == typeof(int))) + propertyValue = Convert.ToInt32(value); + else if (typeof(T).GetFields().Any(f => f.FieldType == typeof(byte))) + propertyValue = Convert.ToByte(value); + else + throw new Exception($"Could not convert enum {value.GetType()} with value {value}"); + } + writer.WritePropertyName(propertyValue.ToString()); } } diff --git a/UnitTests/Tests/Test.cs b/UnitTests/Tests/Test.cs index add1ee97..bde5fd37 100644 --- a/UnitTests/Tests/Test.cs +++ b/UnitTests/Tests/Test.cs @@ -26,5 +26,4 @@ public class Test var result = new JsonUtil().Serialize(_templates); Console.WriteLine(result); } - }