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

Configure Couchbase to use the application's ObjectMapper #24616

Closed
micopiira opened this issue Dec 28, 2020 · 6 comments
Closed

Configure Couchbase to use the application's ObjectMapper #24616

micopiira opened this issue Dec 28, 2020 · 6 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@micopiira
Copy link

Could the CouchbaseAutoConfiguration use existing Jackson ObjectMapper bean instance by default?

Maybe add something like this to the CouchbaseAutoConfiguration class?

@Bean
@ConditionalOnBean(ObjectMapper.class)
public ClusterEnvironmentBuilderCustomizer cluster(ObjectMapper objectMapper) {
  return builder -> builder.jsonSerializer(JacksonJsonSerializer.create(objectMapper));
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 28, 2020
@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Jan 4, 2021
@philwebb
Copy link
Member

philwebb commented Jan 6, 2021

On the surface, this seems like a good suggestion, however, there's a downside. If we auto-configure the builder.jsonSerializer then the user hasn't got a good way to opt-out and go back to the defaults. Unfortunately you can't call builder.jsonSerializer(null).

There's also some interesting logic regarding CryptoManager (see JacksonJsonSerializer.create(CryptoManager cryptoManager).

@micopiira Can you explain a bit more about why you're plugging in the ObjectMapper bean? Do you want specific Jackson customization?

@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue and removed for: team-attention An issue we'd like other members of the team to review labels Jan 6, 2021
@micopiira
Copy link
Author

micopiira commented Jan 7, 2021

@philwebb The default CouchbaseAutoConfiguration does not support serializing Java 8/JSR310 types (Optional, Instant, etc.) out of the box, because the DefaultJsonSerializers ObjectMapper does not register Jdk8Module or JavaTimeModule.

Ofcourse I can configure this myself, but I would expect a Spring Boot application to support this out of the box.

And regarding your earlier comment of opting-out, I guess users could always call builder.jsonSerializer(DefaultJsonSerializer.create()) ?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 7, 2021
@philwebb
Copy link
Member

philwebb commented Jan 7, 2021

Thanks @micopiira, that's useful feedback.

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Jan 7, 2021
@wilkinsona
Copy link
Member

Now that we know that it's easy to restore Couchbase's defaults (thanks for the hint, @micopiira), I think it makes sense for us to configure Couchbase to use Boot's ObjectMapper out of the box.

@philwebb philwebb added type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jan 7, 2021
@philwebb philwebb added this to the 2.5.x milestone Jan 7, 2021
@snicoll snicoll changed the title Autoconfigure Couchbase JsonSerializer Configure Couchbase to use the application's ObjectMapper Jan 8, 2021
@snicoll snicoll self-assigned this Jan 8, 2021
@snicoll snicoll modified the milestones: 2.5.x, 2.5.0-M1 Jan 10, 2021
@sujai1009

This comment has been minimized.

@snicoll

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants