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

Default configuration of AbstractMessageChannelMessagingSendingTemplate leads to Jackson error: "Could not write JSON: Java 8 date/time type java.time.Instant not supported by default" #217

Closed
0ka opened this issue Jan 14, 2022 · 1 comment
Labels
component: sqs SQS integration related issue status: waiting-for-triage Team has not yet looked into this issue type: bug Something isn't working

Comments

@0ka
Copy link

0ka commented Jan 14, 2022

Type: Bug

Component: SQS

Describe the bug
Using Jackson 2.13 and trying to send messages (QueueMessagingTemplate.convertAndSend) that contains fields of Java date/time types lead to the following Jackson error:
"Could not write JSON: Java 8 date/time type java.time.Instant not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling"

According to this ticket spring-projects/spring-boot#26859 Spring normally configure the ObjectMapper bean correct to support Java date/time during serialization.

But the class io.awspring.cloud.messaging.core.support.AbstractMessageChannelMessagingSendingTemplate creates an own MappingJackson2MessageConverter with a default ObjectMapper without using already configured beans.

I would expect that awspring also configure the ObjectMapper to support date/time types if com.fasterxml.jackson.datatype:jackson-datatype-jsr310 is on the class path or better to use an existing ObjectMapper bean.

@github-actions github-actions bot added component: sqs SQS integration related issue type: bug Something isn't working status: waiting-for-triage Team has not yet looked into this issue labels Jan 14, 2022
@maciejwalkowiak
Copy link
Contributor

We are using default ObjectMapper for deserialization, but as QueueMessagingTemplate bean is not created by auto-configuration, you must create it properly to get the support for already registered Jackson modules:

MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setObjectMapper(objectMapper);
converter.setSerializedPayloadClass(String.class);
return new QueueMessagingTemplate(amazonSqs, (ResourceIdResolver) null, converter);

I believe we should auto-configure QueueMessagingTemplate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: sqs SQS integration related issue status: waiting-for-triage Team has not yet looked into this issue type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants