Skip to content

Modernize GlobalDefaultJsonSerializationoptions to .NET 10 and fix Newtonsoft global config - #2113

Closed
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/116863-json-options
Closed

Modernize GlobalDefaultJsonSerializationoptions to .NET 10 and fix Newtonsoft global config#2113
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/116863-json-options

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Modernizes the json-csharp/GlobalDefaultJsonSerializationoptions sample to .NET 10 and fixes the Newtonsoft global-configuration example.

  • Retarget the app and unit-test projects to net10.0; refresh test packages.
  • Configure Newtonsoft globally through AddControllers().AddNewtonsoftJson(...) (package Microsoft.AspNetCore.Mvc.NewtonsoftJson) rather than JsonConvert.DefaultSettings, which only affects direct JsonConvert calls and not the MVC output formatters.
  • SaveProduct now returns Ok(product), so the response goes through the formatter as JSON instead of a hand-serialized string that MVC writes as text/plain.
  • The minimal-API ConfigureHttpJsonOptions uses SnakeCaseUpper to make clear that controller and minimal-API JSON options are independent types.

Build and tests pass on net10.0.

…wtonsoft global config

- Retarget app and tests to net10.0; bump test packages
- Configure Newtonsoft globally via AddControllers().AddNewtonsoftJson (Microsoft.AspNetCore.Mvc.NewtonsoftJson) instead of JsonConvert.DefaultSettings, which does not affect MVC output formatters
- SaveProduct now returns Ok(product) so the response is JSON, not a hand-serialized string written as text/plain
- Use SnakeCaseUpper for the minimal-API ConfigureHttpJsonOptions to show controller and minimal-API options are independent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant