From 3f5952dada1de6835d9e629a2e9a15c080cac6aa Mon Sep 17 00:00:00 2001 From: isabr85 Date: Thu, 29 Jul 2021 11:34:26 +0300 Subject: [PATCH] feat: Ignore case enum parsing Issue scenario: We are serializing our own object (CompanyModel) which contains enum (Pending) with camel-case resolver. The serilalized json string contains now the enum string camel-cased (pending). Now I try to deserialize this json string back to CompanyModel object but I get an error that says that 'pending' enum is missing, but it is not missing it just written as 'Pending' in the Model. We need to ignore case for enum parsing. Can you approve this PR? --- src/Utf8Json/Formatters/EnumFormatter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utf8Json/Formatters/EnumFormatter.cs b/src/Utf8Json/Formatters/EnumFormatter.cs index 861bf026..0a8179e8 100644 --- a/src/Utf8Json/Formatters/EnumFormatter.cs +++ b/src/Utf8Json/Formatters/EnumFormatter.cs @@ -250,7 +250,7 @@ public T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterReso if (!nameValueMapping.TryGetValue(key, out value)) { var str = StringEncoding.UTF8.GetString(key.Array, key.Offset, key.Count); - value = (T)Enum.Parse(typeof(T), str); // Enum.Parse is slow + value = (T)Enum.Parse(typeof(T), str, true); // Enum.Parse is slow } return value; }