aws / aws-lambda-dotnet

Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
Apache License 2.0
1.57k stars 478 forks source link

Use custom serializer options for responses instead of default one #1715

Closed Nairda015 closed 5 months ago

Nairda015 commented 7 months ago

Describe the bug

I don't see a way to set serialization options on all responses from lambda

Expected Behavior

I can control serialization options of responses like DefaultIgnoreCondition

Current Behavior

Default serializer is used and I have no idea how to override it's behavior

Reproduction Steps

Create custom serializer like in this example with DefaultIgnoreCondition set to WhenWrittingNull and return json with null values

Possible Solution

Here I want to use serializer options from custom serializer like in this example instead of default one. It will require changes in if check from first link and maybe here

Additional Information/Context

-

AWS .NET SDK and/or Package version used

Annotation.Framework 1.2

Targeted .NET Platform

.NET 6

Operating System and version

AmazonLinux

ashishdhingra commented 7 months ago

@Nairda015 Good afternoon. Have you tried using LambdaSerializer attribute at method/assembly level? Kindly refer GetSerializerInfoAttribute(), it appears to inspect for LambdaSerializerAttribute.

Thanks, Ashish

Nairda015 commented 7 months ago

Yes I have LambdaSerializerAttribute on assembly level and it works as expected but to populate something different than null here you need to set SerializerJsonContextName and only place in code where it is set is in this strange if statement here

ashishdhingra commented 7 months ago

Yes I have LambdaSerializerAttribute on assembly level and it works as expected but to populate something different than null here you need to set SerializerJsonContextName and only place in code where it is set is in this strange if statement here

Needs review.

normj commented 7 months ago

I agree this is a gap in Annotations to be able to customize the HTTP response body JSON serialization outside if using System.Text.Json's .NET attributes on your POCO for serialization customization.

How would you feel if we allowed adding an interface implementation into the dependency injection container for customizing the serialization options?

Nairda015 commented 7 months ago

Sounds good but why we can't reuse serialization options from custom serializer it is already there

(I updated the links in original comment because there was duplication instead of this example above)

ashishdhingra commented 5 months ago

This should have been addressed via PR https://github.com/aws/aws-lambda-dotnet/pull/1748 and available in Amazon.Lambda.Annotations v1.4.0 package.

github-actions[bot] commented 5 months ago

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.