Closed nikcio closed 1 year ago
Thanks 👍
API controllers for the backoffice use JSON.net by default, so I've used JsonResult
to serialize using System.Text.Json instead. It seems that .AddNewtonsoftJson()
also changes the serializer used for JsonResult
. which is a bit annoying - I didn't know that.
I guess there are different ways to go about fixing this, but adding attributes for both serializers like you've done for this PR seems like an easy fix. I need to find some time for testing this, but looks good to merge.
@nikcio thanks again 👍
Vacation got in the way, but I've now had some time to test and merge this. Personally I'm not a fan of using AddNewtonsoftJson
as it changes the serializer globally, but for people choosing to use it, this PR is a great fix.
I found a few minor issues, which fortunately was quick to fix. For one, the dashboard broke as the pagination
would become Pagination
when using .AddNewtonsoftJson( options => { options.UseMemberCasing(); });
.
When using
.AddNewtonsoftJson()
in our application we encountered that the models wasn't being serialized correctly from Skybrud.Umbraco.Redirects. This is because there was missing theJsonProperty
attribute on theRedirectModel
. HereIsPermanent
andForwardQueryString
was serialized by those names when fetching the redirects and therefore the value was displayed incorrect when viewing a redirect in edit mode.Therefore, I've added attributes to all models that was missing either
JsonProperty
orJsonPropertyName
to preserve consistency in the models no matter what you're using. (System.Text.Json or Newtonsoft.Json).I've tested this in our solution and it works with our setup.
Hope this helps @abjerner 😄
Before:
After: