From afadc1cb431e73b4b7aec8dfaac580b66ac8e1f2 Mon Sep 17 00:00:00 2001 From: Gustau Navarro Date: Mon, 26 Oct 2020 20:56:43 +0100 Subject: [PATCH] Fix OData enum serialization (https://github.com/gustavnavar/Grid.Blazor/issues/221) --- GridShared/Utility/JsonSerializerOptionsExtensions.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/GridShared/Utility/JsonSerializerOptionsExtensions.cs b/GridShared/Utility/JsonSerializerOptionsExtensions.cs index 65a493fc..4a777157 100644 --- a/GridShared/Utility/JsonSerializerOptionsExtensions.cs +++ b/GridShared/Utility/JsonSerializerOptionsExtensions.cs @@ -20,6 +20,12 @@ public static JsonSerializerOptions AddOdataSupport(this JsonSerializerOptions j // required for Blazor WA jsonOptions.Converters.Add(new ODataDateTimeConverter()); + converters = jsonOptions.Converters.Where(r => r.CanConvert(typeof(Enum))); + if (converters != null) + for (int i = converters.Count() - 1; i >= 0; i--) + { + jsonOptions.Converters.Remove(converters.ElementAt(i)); + } jsonOptions.Converters.Add(new JsonStringEnumConverter(null)); return jsonOptions; }