Try our conversational search powered by Generative AI!

UI depending to much on set json serialization naming policy


When migrating a project to CMS 12 we added the following in ConfigureServices to make our apis behave as in .NET 11

services.AddMvc().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);

I though everything worked fine until i went to edit a content type (/EPiServer/EPiServer.Cms.UI.Admin/default#/ContentTypes/edit-content-type/<typeid>) which called the api /EPiServer/EPiServer.Cms.UI.Admin/AllowedTypes.

The calling javscript (/EPiServer/EPiServer.Cms.UI.Admin/12.25.1/clientResources/dist/admin.bundle.js) threw an exception because it was expecting the json returned to be in camel case but instead got pascal case.

This is so far the only requst that seem to fail because of this. Other optimizely admin requests seems to work either because they return camel case even thought this setting is in place or they can handle pascal case. 

We can of course solve this problem by switching to camel case as a default naming policy and adjust our internal apis but i think the choice of naming policy shouldn't be determined by optimizely. Their api's should specify camel case directly with JsonPropertyNames or similar.

Dec 12, 2023 10:15

You should not set globally. You can set the json options per assembly which wont affect other parts of the cms.

services.UseSystemTextJsonSerialization(typeof (MyTypeInWebProject).Assembly, (Action<JsonSerializerOptions>) (settings =>
       settings.PropertyNamingPolicy = (JsonNamingPolicy) null;
Dec 12, 2023 17:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.