diff --git a/Lambdas/GetCharityTypes/Function.cs b/Lambdas/GetCharityTypes/Function.cs index c4c0540..c7f6ca3 100644 --- a/Lambdas/GetCharityTypes/Function.cs +++ b/Lambdas/GetCharityTypes/Function.cs @@ -8,6 +8,7 @@ using System.Text.Json.Serialization.Metadata; using System.Text.Json.Serialization; using Amazon.Lambda.APIGatewayEvents; + namespace GetCharityTypes; public class Function @@ -33,8 +34,11 @@ private static async Task Main(string[] args) _connectionString = $"Server={_dbHost};Port={_dbPort};Database={_dbName};" + $"User={_dbUser};Password={authToken};SSL Mode=Required;"; - Func> handler = FunctionHandler; - await LambdaBootstrapBuilder.Create(handler, new SourceGeneratorLambdaJsonSerializer()).Build().RunAsync(); + // Use the source generator serializer + await LambdaBootstrapBuilder.Create( + FunctionHandler, + new SourceGeneratorLambdaJsonSerializer() + ).Build().RunAsync(); } public static async Task FunctionHandler(ILambdaContext context) @@ -45,7 +49,6 @@ public static async Task FunctionHandler(ILambdaContext context) using (MySqlConnection connection = new MySqlConnection(_connectionString)) { await connection.OpenAsync(); - string sql = "SELECT id, name FROM types"; using (MySqlCommand command = new MySqlCommand(sql, connection)) { @@ -67,20 +70,26 @@ 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); + + // Use the source generator serialization + return JsonSerializer.Serialize(types, CustomSerializerContext.Default.ListCharityType); } } + [JsonSerializable(typeof(APIGatewayProxyRequest))] [JsonSerializable(typeof(APIGatewayProxyResponse))] [JsonSerializable(typeof(CharityType))] +[JsonSerializable(typeof(List))] public partial class CustomSerializer : JsonSerializerContext { - } + +//[JsonSerializable(typeof(List))] +//[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] +//public partial class CustomSerializerContext : JsonSerializerContext +//{ +//} + public class CharityType { public int Id { get; set; }