tags

Serialization

Using multiple JSON serialization settings in ASP.NET Core

My blog has been a bit quiet in the last 18 months or so, because, well, life happened… In that time span I became a father, changed jobs twice, and relocated to Canada with my family, so free time has been scarce. Anyway, I recently ran into a problem that I found worthy of a blog post, and I have a bit of time to write! Heterogenous JSON formats Let’s say we’re building an ASP.

C# 9 records as strongly-typed ids - Part 3: JSON serialization

Created by Wireform from the Noun Project Using C# 9 records as strongly-typed ids
In the previous post in this series, we noticed that the strongly-typed id was serialized to JSON in an unexpected way: { "id": { "value": 1 }, "name": "Apple", "unitPrice": 0.8 } When you think about it, it’s not really unexpected: the strongly-typed id is a “complex” object, not a primitive type, so it makes sense that it’s serialized as an object. But it’s clearly not what we want… Let’s see how to fix that.