Skip to content

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

Merged
merged 1 commit into from
May 5, 2021

Conversation

mikereiche
Copy link
Collaborator

Expose ObjectMapper used by JsonSerializer

Closes #1130.

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@mikereiche mikereiche requested a review from daschl April 23, 2021 20:45
if (!nonShadowedJacksonPresent()) {
throw new CouchbaseException("non-shadowed Jackson not present");
}
builder.jsonSerializer(JacksonJsonSerializer.create(couchbaseObjectMapper));
Copy link
Collaborator Author

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

Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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.

Copy link
Contributor

@daschl daschl left a 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");
Copy link
Contributor

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?

Copy link
Collaborator Author

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

@mikereiche mikereiche force-pushed the datacouch_1130_expose_object_mapper branch from 869c0ab to 4b121c0 Compare April 26, 2021 13:40
@mikereiche mikereiche merged commit a806631 into main May 5, 2021
mikereiche added a commit that referenced this pull request Aug 9, 2021
@mikereiche mikereiche deleted the datacouch_1130_expose_object_mapper branch August 11, 2021 22:08
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

Successfully merging this pull request may close these issues.

add couchbaseJsonValueModule bean to AbstractCouchbaseConfiguration
2 participants