SaaS CMS has officially launched! Learn more now.

ContentApiModel json formatted incorrectly


We have a weird issue with formatting of ContentApiModel to JSON.

// Startup.cs
services.UseNewtonsoftSerialization(assembly, settings =>
	settings.Converters.Add(new StringEnumConverter(new DefaultNamingStrategy()));
	settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
	settings.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
	settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
// api controller, _contentApiOptions is injected in constructor

public IActionResult GetAll([FromRoute] int? contentLinkId = null)
	var content = new List<ContentApiModel>();
	var language = LanguageSelector.AutoDetect(true).Language;
	foreach (var page in GetAllResellers(contentLinkId))
		var model = _contentConverter.Convert(page, new ConverterContext(page.ContentLink, language, _contentApiOptions, 
			ContextMode.Default, null, "*", false));

	return new JsonFormattedResult(content);

Resulting JSON, some properties are propper CamelCase - some are not.

Any ideas?

Aug 16, 2023 7:57
Carl S - Aug 16, 2023 8:05
All the custom added page properties is not proper camelcase.
Carl S - Aug 16, 2023 12:20
Are you supposed to use something else than 'DefaultContentConverter' or 'JsonFormattedResult' to get it to format correctly.

Try setting this way, I think content delivery uses its own settings.

 services.ConfigureContentDeliveryApiSerializer(settings =>
                settings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
Aug 16, 2023 14:33

Interesting. Did not know about that configuration option - the content delivery api response is however is correct.

This is a custom api controller. - The answer after a long search was this.

Use the DefaultContractResolver, with a CamelCaseNamingStrategy and all ctor parameters to 'true'.

Edited, Aug 17, 2023 4:23
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.