Skip to content
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

Sqs messages deserialization to LocalDateTime does not work #905

Closed
atakume opened this issue Oct 5, 2023 · 3 comments
Closed

Sqs messages deserialization to LocalDateTime does not work #905

atakume opened this issue Oct 5, 2023 · 3 comments

Comments

@atakume
Copy link

atakume commented Oct 5, 2023

Type: Bug

Component:
"SQS"

Describe the bug
Using spring cloud (spring-cloud-aws-starter-sqs) with version 3.0.2 for my async Sqs listener (annotated with @SqsListener) I face an issue with deserialization of LocalDateTime and setting up proper ObjectMapper for the process.

[sdk-async-response-0-3] ERROR i.a.c.s.l.s.AbstractPollingMessageSource - Error processing message
org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Java 8 date/time type java.time.LocalDateTime not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling

How can I configure custom (or even default spring) objectMapper for deserialization?

Sample
My listener method:

@Component 
class Example{
@SqsListener(value = "${queue}")
    public CompletableFuture<Void> populateNewsActivity(List<Msg> messages) {
    ....
   }
}

I tried by setting up configuration:

@Bean
SqsListenerConfigurer configurer(ObjectMapper objectMapper) {
    return registrar -> registrar.setObjectMapper(objectMapper);
}

And by providing custom MappingJackson2MessageConverter like:

@Bean
    MappingJackson2MessageConverter mappingJackson2MessageConverter(ObjectMapper objectMapper) {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setObjectMapper(objectMapper);
        converter.setPrettyPrint(true);
        return converter;
 }

In both cases I got the same error (my configuration was omitted).

@neiljbrown
Copy link
Contributor

Hi @atakume, this is a known issue which is in the process of being addressed. See #721. In the meantime that ticket contains a couple of suggested workarounds (read from the top), including one I contributed here.

Regards, Neil.

@atakume
Copy link
Author

atakume commented Oct 5, 2023

Hi @neiljbrown, thanks I'll try this way.
I missed this one while searching 🙈

@atakume
Copy link
Author

atakume commented Oct 5, 2023

I'm closing this one as it's duplicate of known issue

@atakume atakume closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants