awspring / spring-cloud-aws

The New Home for Spring Cloud AWS
http://awspring.io
Apache License 2.0
891 stars 303 forks source link

S3EventNotification deserialization no longer works with AWS SDK v2 S3 Event Notification #1278

Open helpermethod opened 4 days ago

helpermethod commented 4 days ago

Type: Bug

Component: SQS

Describe the bug S3EventNotification is no longer correctly deserialized when switching from com.amazonaws:aws-java-sdk-s3 to software.amazon.awssdk:s3-event-notifications.

This is due to the following changes: https://aws.amazon.com/de/blogs/developer/the-aws-sdk-for-java-2-17-removes-its-external-dependency-on-jackson/

Because the constructor and fields are no longer annotated with @JsonCreator and @JsonProperty, Jackson is no longer able to map the JSON correctly.

It's easy to work around it by accepting a String instead of a S3EventNotification in the listener and then performing the deserialization by calling S3EventNotification.fromJson but it would be nicer this wouldn't be needed.

@SqsListener("\${sqs.currents.notifications.processed.queueName}")
fun listen(s3EventNotificationJson: String) {
    val s3EventNotification = S3EventNotification.fromJson(s3EventNotificationJson)

    copyService.copy(s3EventNotification.records.first())
}

One solution could be to provide a custom JSON Deserializer for that case. Wouldn't mind creating a PR.

tomazfernandes commented 4 days ago

Hey @helpermethod, thanks for bringing this up, your PR is welcome!

tomazfernandes commented 4 days ago

Just one comment @helpermethod - if I understand the feature correctly, I think the best way to handle this might be having an ArgumentResolver, similar to what we do with AcknowledgmentHandlerMethodArgumentResolver.

Makes sense?

helpermethod commented 2 days ago

Hi @tomazfernandes,

I guess I also need to register the argument resolver in AbstractListenerAnnotationBeanPostProcessor?