54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
|
#define RGG4F // RGG4 RGG4F
|
||
|
#if NEVER
|
||
|
#elif RGG4
|
||
|
// <snippet_1>
|
||
|
using System.Text.Json.Serialization;
|
||
|
|
||
|
var builder = WebApplication.CreateSlimBuilder(args);
|
||
|
|
||
|
builder.Services.ConfigureHttpJsonOptions(options =>
|
||
|
{
|
||
|
options.SerializerOptions.TypeInfoResolverChain.Insert(0,
|
||
|
AppJsonSerializerContext.Default);
|
||
|
});
|
||
|
|
||
|
var app = builder.Build();
|
||
|
|
||
|
app.MapGet("/v1/todos", () => new { Id = 1, Task = "Write tests" });
|
||
|
|
||
|
app.Run();
|
||
|
|
||
|
record Todo(int Id, string Task);
|
||
|
[JsonSerializable(typeof(Todo[]))]
|
||
|
internal partial class AppJsonSerializerContext : JsonSerializerContext
|
||
|
{
|
||
|
|
||
|
}
|
||
|
// </snippet_1>
|
||
|
#elif RGG4F
|
||
|
// <snippet_1f>
|
||
|
using System.Text.Json.Serialization;
|
||
|
|
||
|
var builder = WebApplication.CreateSlimBuilder(args);
|
||
|
|
||
|
builder.Services.ConfigureHttpJsonOptions(options =>
|
||
|
{
|
||
|
options.SerializerOptions.TypeInfoResolverChain.Insert(0,
|
||
|
AppJsonSerializerContext.Default);
|
||
|
});
|
||
|
|
||
|
var app = builder.Build();
|
||
|
|
||
|
app.MapGet("/v1/todos", () => new Todo(1, "Write tests fix"));
|
||
|
|
||
|
app.Run();
|
||
|
|
||
|
record Todo(int Id, string Task);
|
||
|
[JsonSerializable(typeof(Todo[]))]
|
||
|
internal partial class AppJsonSerializerContext : JsonSerializerContext
|
||
|
{
|
||
|
|
||
|
}
|
||
|
// </snippet_1f>
|
||
|
#endif
|