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));
}

Comment From: philwebb

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?

Comment From: micopiira

@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()) ?

Comment From: philwebb

Thanks @micopiira, that's useful feedback.

Comment From: wilkinsona

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.

Comment From: sujai1009

Hi Team what is the solution to this problem. i am facing this problem. And even i configure ObjectMapper with jsr30 modules, i when i save the data to repository its not working. getting error

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type java.time.OffsetDateTime not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.HashMap["records"]->java.util.ArrayList[0]->java.util.HashMap["timestamp"])

Kindly help me

Comment From: snicoll

@sujai1009 please ask questions on StackOverflow.