From 08024e42bcf5c748fbe03b7ee6ffae273fcd55b6 Mon Sep 17 00:00:00 2001 From: RobKraft Date: Tue, 3 Dec 2024 19:43:59 -0600 Subject: [PATCH] try another way to serialize --- Lambdas/GetCharityTypes/Function.cs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Lambdas/GetCharityTypes/Function.cs b/Lambdas/GetCharityTypes/Function.cs index 650b045..a9b96ad 100644 --- a/Lambdas/GetCharityTypes/Function.cs +++ b/Lambdas/GetCharityTypes/Function.cs @@ -5,7 +5,9 @@ using Amazon.RDS.Util; using Amazon; using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.Json.Serialization.Metadata; +using System.Text.Json.Nodes; namespace GetCharityTypes; public class Function @@ -35,6 +37,7 @@ private static async Task Main(string[] args) await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer()).Build().RunAsync(); } + public static async Task FunctionHandler(ILambdaContext context) { List types = new List(); @@ -65,15 +68,25 @@ public static async Task FunctionHandler(ILambdaContext context) { Console.WriteLine($"connstring={_connectionString} and error: {ex.Message}"); } - var options = new JsonSerializerOptions - { - TypeInfoResolver = null // Enables reflection-based serialization - }; - return JsonSerializer.Serialize(types, options); + var jsonNode = JsonNode.Parse(JsonSerializer.Serialize(types)); + string json = jsonNode.ToJsonString(); + return json; } } -public class CharityType +[JsonSourceGenerationOptions( + WriteIndented = true, + PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, + GenerationMode = JsonSourceGenerationMode.Serialization)] +[JsonSerializable(typeof(CharityType))] +public class CharityType //: JsonSerializerContext { public int Id { get; set; } public string Type { get; set; } = string.Empty; -} \ No newline at end of file + + //protected override JsonSerializerOptions? GeneratedSerializerOptions => throw new NotImplementedException(); + + //public override JsonTypeInfo? GetTypeInfo(Type type) + //{ + // throw new NotImplementedException(); + //} +}