Skip to content

CAMEL-22090: Fix couchbase consumer when Jackson is on classpath#21965

Merged
gnodet merged 1 commit intomainfrom
camel-22090-couchbase-jackson
Mar 13, 2026
Merged

CAMEL-22090: Fix couchbase consumer when Jackson is on classpath#21965
gnodet merged 1 commit intomainfrom
camel-22090-couchbase-jackson

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Mar 13, 2026

Summary

  • Fixed the Couchbase consumer to avoid using the shaded Jackson JsonNode class for view key deserialization, using String.class instead which works regardless of which Jackson serializer is active
  • Extracted ClusterEnvironment creation into a dedicated createClusterEnvironment() method with documentation explaining why DefaultJsonSerializer is explicitly configured to prevent the Couchbase SDK from auto-detecting non-shaded Jackson on the classpath
  • Added a unit test verifying the ClusterEnvironment uses DefaultJsonSerializer (wrapped in JsonValueSerializerWrapper) instead of the auto-detected JacksonJsonSerializer

Details

When Jackson is on the classpath (e.g., via camel-jackson, Spring Boot, or Quarkus), the Couchbase SDK auto-detects it and uses JacksonJsonSerializer backed by the non-shaded Jackson ObjectMapper. This causes deserialization failures because the consumer code was using row.keyAs(JsonNode.class) where JsonNode is the shaded class (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode), which the non-shaded Jackson cannot deserialize into.

The fix addresses this at two levels:

  1. Consumer level: Replaced row.keyAs(JsonNode.class).get().asText() with row.keyAs(String.class).orElse(null), eliminating the dependency on shaded Jackson types for key extraction
  2. Environment level: Kept the DefaultJsonSerializer configuration (from CAMEL-22083) but refactored it into a well-documented, testable method

Test plan

  • Unit tests pass (27 tests, 0 failures)
  • Integration tests with Couchbase container (require testcontainers)
  • Manual verification with Jackson on the classpath

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Copy link
Contributor Author

@gnodet gnodet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: DefaultJsonSerializer (which uses the shaded Jackson) was already explicitly configured in the existing code. The real fix here is changing row.keyAs(JsonNode.class).get().asText() to row.keyAs(String.class).orElse(null) in the consumer, which avoids depending on the shaded JsonNode class entirely.

There is no valid use case for users wanting the Couchbase SDK to use non-shaded Jackson, since all SDK internal types depend on the shaded version. Using String.class for view row keys is safe — keys are typically strings or simple JSON values, and the result is set as a String header anyway.

The endpoint method extraction (createClusterEnvironment()) is optional refactoring for testability but not strictly needed for the fix.

@gnodet gnodet marked this pull request as ready for review March 13, 2026 08:03
@gnodet gnodet added the bug Something isn't working label Mar 13, 2026
@gnodet gnodet merged commit 257c2b3 into main Mar 13, 2026
4 checks passed
@gnodet gnodet deleted the camel-22090-couchbase-jackson branch March 20, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants