Skip to content

Custom JsonConverter: .NET 10 and registration tests - #2260

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/84794-json-dotnet-create-custom-jsonconverter
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/84794-json-dotnet-create-custom-jsonconverter

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for the article "How to Create a Custom JsonConverter in Json.NET" (https://code-maze.com/json-dotnet-create-custom-jsonconverter/). Touches only json-csharp/CustomJsonConverter.

Changes:

  • Both projects retargeted from net7.0 to net10.0.
  • Newtonsoft.Json 13.0.3 to 13.0.4 in both projects.
  • Microsoft.AspNetCore.Mvc.Testing removed from the test project. Nothing in either test file uses it.
  • SmartContactConverter loses its CanWrite and CanRead overrides. Both returned true, which is already the base class default.
  • New ConverterRegistrationUnitTest.cs: one test registers SmartContactConverter through JsonSerializerSettings.Converters and asserts the same output as the per-call test; one test round-trips a record carrying [JsonConverter(typeof(ImprovedContactConverter))].

Package versions, re-queried on NuGet on 2026-10-04 (newest stable on that day):

  • Newtonsoft.Json 13.0.4
  • Microsoft.NET.Test.Sdk 18.10.1
  • xunit 2.9.3
  • xunit.runner.visualstudio 4.0.0
  • coverlet.collector 10.1.0

Local run on SDK 10.0.302, runtime 10.0.10: build 0 warnings 0 errors, dotnet test Passed 6, Failed 0. dotnet list package --vulnerable --include-transitive reports nothing for either project.

- Retarget both projects from net7.0 to net10.0.
- Newtonsoft.Json 13.0.3 to 13.0.4.
- Test packages: Microsoft.NET.Test.Sdk 18.10.1, xunit 2.9.3,
  xunit.runner.visualstudio 4.0.0, coverlet.collector 10.1.0.
- Remove the unused Microsoft.AspNetCore.Mvc.Testing reference.
- Drop the CanWrite and CanRead overrides from SmartContactConverter;
  both repeat the base class defaults.
- Add ConverterRegistrationUnitTest: a converter registered through
  JsonSerializerSettings.Converters, and a type carrying the
  JsonConverter attribute.
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