Skip to content

Property ordering in JSON: net10.0, MSTest 4.3.3, converter Read() fix - #2156

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/86549-property-order
Open

Property ordering in JSON: net10.0, MSTest 4.3.3, converter Read() fix#2156
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/86549-property-order

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Updates the sample for json-csharp/OrderPropertyJsonInCSharp alongside a rewrite of the article Property Ordering in C# JSON Serialization.

  • All three projects retargeted net7.0 -> net10.0.
  • Package bumps (versions re-queried from the NuGet flat-container API at prep time): Newtonsoft.Json 13.0.3 -> 13.0.4, BenchmarkDotNet 0.13.5 -> 0.15.8, Microsoft.NET.Test.Sdk 17.3.2 -> 18.9.0, MSTest.TestAdapter/MSTest.TestFramework 2.2.10 -> 4.3.3, coverlet.collector 3.1.2 -> 10.0.1. The MSTest jump crosses two majors; the existing six tests use only Assert.AreEqual and needed no rewrite, and the build emits zero MSTESTxxxx analyzer diagnostics.
  • Bug fix. MicrosoftOrderedPropertiesConverter<T>.Read() called JsonSerializer.Deserialize<T>(ref reader, options) with the same options instance the converter is registered in, so deserializing re-entered the converter. It does not throw a catchable exception: it recurses until the process dies with Stack overflow., reproduced through both the options Converters collection and the [JsonConverter] attribute. Read() now throws NotSupportedException with a message saying the converter exists to control write order. The six existing tests only serialize, so nothing caught this; a seventh test now covers it.
  • Typo in a public member: Student.RegistratioNumber -> RegistrationNumber. The name is printed in the article's console output, so the article, the snippet and the output block move with it.

dotnet build 0 warnings, 0 errors and dotnet test 7/7 green on SDK 10.0.302 / runtime 10.0.10. Benchmark re-run on .NET 10 with BenchmarkDotNet 0.15.8; the article's figures are replaced with the new run.

…ter Read() re-entry

- All three projects net7.0 -> net10.0
- Newtonsoft.Json 13.0.3 -> 13.0.4, BenchmarkDotNet 0.13.5 -> 0.15.8,
  Microsoft.NET.Test.Sdk 17.3.2 -> 18.9.0, MSTest.TestAdapter/TestFramework
  2.2.10 -> 4.3.3, coverlet.collector 3.1.2 -> 10.0.1
- MicrosoftOrderedPropertiesConverter<T>.Read() called
  JsonSerializer.Deserialize<T> with the same options the converter is
  registered in, so deserializing re-entered the converter and recursed until
  the process died with a stack overflow. It now throws NotSupportedException;
  the converter exists to control write order only. One test covers it.
- Typo in a public member: Student.RegistratioNumber -> RegistrationNumber
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