Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Can you share the class defintion for SectionBackground for context?
Possibly a type conversion issue if the enum was originally serialized as a JSON string.
Trying enabling the behaviour in the .NET Core serializer - https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/migrate-from-newtonsoft?pivots=dotnet-9-0#allow-or-write-numbers-in-quotes
services
.AddMvc()
.AddJsonOptions(o => o.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString);
Added the definition in the original post (at the top). It's just a simple enum with two values (None/0, Filled/1).
Changing the option didn't help.
Another thing i forgot to mention: it works when setting the enum field to Filled/1. If set to None/0, it errors. Is it some wierd null-handling/default-value issue?
This is where it errors out, even before I changed the option:
Either the option is on by default or it's ignoring these options at this stage in the UI (it looks like they're adding a bunch of their own converters as services in AddCmsUI()?)
What does your editor descriptor do? Enums should work OOTB, no need for custom serialization or editor descriptors.
Much of this is orignially developed by various agencies over the years, from CMS 6 and on.
But I guess it is there to get a proper selection editor?
If I remove the attribute I get a regular numeric textbox (+/-).
Likely some custom code which is causing this weird behaviour.
Try changing the code where it errors to use the TryGetInt32 method instead and return default value of 0 if the method returns false. As you say if it only fails when set to None (0), this may be the quickest fix.
Sorry I wasn't clear, but that bit of code is part of System.Text.Json.Serialization.Converters.Int32Converter, so a bit hard to change. :-)
But I think I have found why this is happening.
It seems the custom enum SelectionFactory renders the options in a somewhat hacky fashion.
As in, if the first value has the name "None", it gets an empty string value.
I guess the Newtonsoft variant just assigns it the default value either way.
Hi
We have recently upgraded from CMS 11 to 12.
We're getting serialization error when trying to save a block containing an enum.
The backing type is integer.
The easy fix is adding preferredUiJsonSerializerType="Newtonsoft" to module.config.
But the question is: how would a fix this using the Core built-in serializer? I have tried adding a converter in JsonOptions, as a converter and as a converter factory, as well as a service. But the converter is never called? Obviously without the above change to module.config, or set to "Net".