1 hour ago · 17 min read3355 words · Tech · hide · 0 comments

This is the seventh post in the series: Exploring the .NET 11 preview. Part 1 - Running background tasks in Blazor with Web WorkersPart 2 - .NET (OK, C#) finally gets union types🎉Part 3 - Avoiding ToString() allocations with StringBuilder.MoveChunksPart 4 - Closed class hierarchiesPart 5 - Improvements to reading Process outputsPart 6 - Automatic CSRF protection based on Fetch Metadata headersPart 7 - The pain of serializing unions and closed class hierarchies with System.Text.Json (this post) .NET 11 and C# 15 are adding support for both union types and closed class hierarchies. In this post I look at how System.Text.Json handles these new type hierarches, the differences between them, as well as some of the sharp edges to watch out for. It's probably just me, but I found the whole experience quite painful. I start by giving a recap on union types and closed class hierarchies. I then create simple examples of each, and try to serialize them with System.Text.Json. I then play…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.