77 days ago · 17 min read3355 words · Tech · hide · Fediverse post

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…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town