-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The LambdaSerializer attribute is ignored #1582
Comments
Needs review with the team. Most likely a feature request. |
@ashishdhingra The sourcegenerator raises this diagnostic error when the serializer attribute is not specified: You are required to register a serializer with the attribute. If the diagnostic exists to report an error on "the JSON serializer for Lambda events" not being registered, and then when registered that serializer is ignored. This looks and feels like a bug. You have a documented feature that does not work. Currently, as this feature does not work - the only way to handle custom serialization of incoming requests is to litter request models with json serializer attributes. This is not possible when the models come from another source (e.g. an external nuget package). It's either a bug that the attribute is required, or it's a bug that the feature is not implemented as documented. |
@ashishdhingra I think it is fair to consider this a bug that when serializing the IHttpRequest we are not honoring the registered ILambdaSerializer. |
We should perhaps fix the issue #1572 as well along with this issue. |
P1 feature request considering the PR for issue #1572 is merged first. |
Any update on this? currently having the same problem in net 8 and latest aws packages |
@Kieranties I was lucky enough to get the following packages released today!
Now everything seems to work as expected! I need to do a more deep testing session, I'll report if i found something strange |
This has been fixed as of version 1.1.0 of Amazon.Lambda.Annotations. The Visual Studio template will be updated to use the latest version of Amazon.Lambda.Annotations as part of the upcoming .NET 8 Lambda support. |
Comments on closed issues are hard for our team to see. |
Describe the bug
The LambdaSerializer attribute is explicitly ignored in the code base.
This means there is no way to customize the serialization of incoming request bodies. The functionality detailed here does not appear to be possible.
Expected Behavior
At the assembly level, specifying a custom serializer implementation should be honoured.
e.g. Adding
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
should use an instance ofAmazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer
to perform serialization duties.Current Behavior
Any customization is fully ignored.
Reproduction Steps
Result: customizations are not used.
Possible Solution
I've taken a look at this today and a trivial (though likely incorrect) way to grab the type defined in the attribute registered at the assembly level is to resolve the attribute value like so:
And then assign to the model:
A small change to the templates where body responses are being processed is required e.g. in an incoming request
And I thought I was good... I can switch out the type for my own custom implementation but... what is the contract to honour for the serializer?
I originally used
Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer
but the contract for serialization requires a stream, which is not required when calling the defaultSystem.Text.Json.Serializer
.I can of course implement my own type that honours the same contract as
System.Text.Json.Serializer
but it feels to me the user should be guided a little better. i.e the serializer should be checked that the type registered implements a given interface.System.Text.Json.Serializer
has no interface.Is it worth investigating alternative resolution paths for customization? Such as an attribute to specify serializer options for a method or assembly, or even allowing the options to be resolved from the container?
Additional Information/Context
I'm keen to have this fixed and am happy to contribute changes as required to get it done.
AWS .NET SDK and/or Package version used
Amazon.Lambda.Annotations 1.0.0
Targeted .NET Platform
net6.0
Operating System and version
Windows 11
The text was updated successfully, but these errors were encountered: