From the course: Advanced .NET: Commands, C# Enhancements, Web Apps, and Libraries

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

JSON updates: Create JsonSerializerContext classes

JSON updates: Create JsonSerializerContext classes - .NET Tutorial

From the course: Advanced .NET: Commands, C# Enhancements, Web Apps, and Libraries

JSON updates: Create JsonSerializerContext classes

- This is the class that I want to serialize. It's called the food class. It has food name, calories, and category as the properties. So the first step is to create this public class here. And then I create another class called food generation context that drives from JSUN serializer context. And I indicate what type of want to serialize. That's what I'm doing here in line 20. And I also indicate any serialization options here. I want to write indented equal true. And I want to use camel casing or names. So this is called Foods Generation Context. And you notice it's marked as a partial class because the source generator's going to create the rest of the cup. I'm also going to to serialize an eye innumerable of food. So I do the same thing, here I call this one Foods Generation Context and everything else is the same, except for the type where I said, type of IEnumerable food. So that's it. Now let's go up here and…

Contents