-
Notifications
You must be signed in to change notification settings - Fork 192
Expose ObjectMapper used by JsonSerializer #1132
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
Conversation
if (!nonShadowedJacksonPresent()) { | ||
throw new CouchbaseException("non-shadowed Jackson not present"); | ||
} | ||
builder.jsonSerializer(JacksonJsonSerializer.create(couchbaseObjectMapper)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the couchbaseObjectMapper from the new Bean.
Check for nonShadowedJacksonPresent() although it should never happen.
} | ||
return mapper; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the couchbaseObjectMapper that gets used and exposed. Created the same as in ClusterEnvironment.Builder.
@@ -184,6 +184,7 @@ void findByTypeAlias() { | |||
vie = new Airport("airports::vie", "vie", "loww"); | |||
vie = airportRepository.save(vie); | |||
List<Airport> airports = couchbaseTemplate.findByQuery(Airport.class) | |||
.withConsistency(QueryScanConsistency.REQUEST_PLUS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed a test that was sporadically failing.
@@ -198,7 +199,7 @@ void findByEnum() { | |||
vie = new Airport("airports::vie", "vie", "loww"); | |||
vie = airportRepository.save(vie); | |||
Airport airport2 = airportRepository.findByIata(Iata.vie); | |||
assertNotNull(airport2, "should have found "+vie); | |||
assertNotNull(airport2, "should have found " + vie); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting. Nothing to see.
List<Airport> airports1 = airportRepository.findAllByIata("vie").collectList().block(); | ||
assertEquals(saved, airports1.get(0)); | ||
Airport airport1 = airportRepository.findById(saved.getId()).block(); | ||
assertEquals(airport1, saved); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was using a query which requires an index, but if you run this test by itself, there won't be an index. Switch to use kv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some clarifications/input
@@ -130,6 +140,10 @@ public Cluster couchbaseCluster(ClusterEnvironment couchbaseClusterEnvironment) | |||
@Bean(destroyMethod = "shutdown") | |||
public ClusterEnvironment couchbaseClusterEnvironment() { | |||
ClusterEnvironment.Builder builder = ClusterEnvironment.builder(); | |||
if (!nonShadowedJacksonPresent()) { | |||
throw new CouchbaseException("non-shadowed Jackson not present"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason we need to blow up if it is not present? (or just add the custom serializer if present?) - could log a warning instead if unlikely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. In the SDK, when the non-shadowed jackson classes are not present, a DefaultJsonSerializer is created. DefaultJsonSerializer has no means to use an already-created mapper, or expose the mapper that it creates. I suppose this would only be an issue when the user wants to us couchbaseObjectMapper() and expects it to be the same one used by the serializer. However, David said the not having the non-shadowed classes in Spring is impossible. The alternative would be to issue a warning saying that the serializer was not using couchbaseObjectMapper() and continue.
return nonShadowedJacksonPresent()
? JacksonJsonSerializer.create(cryptoManager)
: DefaultJsonSerializer.create(cryptoManager);
src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java
Outdated
Show resolved
Hide resolved
869c0ab
to
4b121c0
Compare
Closes #1130. Co-authored-by: mikereiche <[email protected]>
Expose ObjectMapper used by JsonSerializer
Closes #1130.