Serialize enum to string

Hi Radzen :v:

I have an entity with an enum property. When posting the entity to the server, I have an invalid ModelState, with the following error message:

Exception = "Cannot read the value '0' as a quoted JSON string value."

Inspecting the request body I see the property gets serialized to an int, and from looking around it seems OData expects an enum to be serialized to a string.

Passing in the following options to ODataJsonSerializer.Serialize in my AppDbService.cs didn't have any effect.

JsonSerializerOptions options = new JsonSerializerOptions
{
    Converters = { new JsonStringEnumConverter() }
};

When adding the following attribute to the property, I was able to get the serializer to convert it to its string representation.

[JsonConverter(typeof(JsonStringEnumConverter))]

Not sure if this behaviour is expected, or whether this might just assist someone in the future.

Serializing the enum as a string, breaks the PATCH request for the entity, with an exception being thrown in here in EntityPatch.cs:

https://github.com/radzenhq/radzen-examples/blob/a342c54d46785c2c1ec07a855915681a9d930bc5/BlazorCRMWasm/server/Data/EntityPatch.cs#L73

The exception message is:
"The given key '4' was not present in the dictionary."

Hi @damian_s,

Could you send us a sample application that reproduces the issue to info@radzen.com? The BlazorCRMWasm one doesn't use enums so it won't be of much help.

Hi @korchev,

Sure, I've sent a sample project along.

We haven't received anything yet. Make sure that the project is less than 20 MB in size (delete any obj and bin directories).

Strange. I'll send it again. It's a small sample project - probably about 2MB.

Seems like something was out of sync when I received the errors on the PATCH requests. Everything now just works.

Thanks for taking a look.