I have tried to implement Source Generation-based JSON serilization, based on MS Docs: How to use source generation in System.Text.Json. My code is as follows:
using System;
using System.Text.Json;
var person = new Person(){FirstName = "John", LastName = "Shepard"};
Console.WriteLine(JsonSerializer.Serialize(person));
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
And my SerializationContext:
[JsonSerializable(typeof(Person))]
public partial class PersonJsonContext : JsonSerializerContext
{
}
I have the System.Text.Json
version 6.0.0 installed in my project.
But when running dotnet build
, no code is generated in my PersonJsonContext
class. Where can I find the generated code?