CAMEL-22090: Fix couchbase consumer when Jackson is on classpath#21965
CAMEL-22090: Fix couchbase consumer when Jackson is on classpath#21965
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
gnodet
left a comment
There was a problem hiding this comment.
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.
Summary
JsonNodeclass for view key deserialization, usingString.classinstead which works regardless of which Jackson serializer is activeClusterEnvironmentcreation into a dedicatedcreateClusterEnvironment()method with documentation explaining whyDefaultJsonSerializeris explicitly configured to prevent the Couchbase SDK from auto-detecting non-shaded Jackson on the classpathClusterEnvironmentusesDefaultJsonSerializer(wrapped inJsonValueSerializerWrapper) instead of the auto-detectedJacksonJsonSerializerDetails
When Jackson is on the classpath (e.g., via camel-jackson, Spring Boot, or Quarkus), the Couchbase SDK auto-detects it and uses
JacksonJsonSerializerbacked by the non-shaded JacksonObjectMapper. This causes deserialization failures because the consumer code was usingrow.keyAs(JsonNode.class)whereJsonNodeis 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:
row.keyAs(JsonNode.class).get().asText()withrow.keyAs(String.class).orElse(null), eliminating the dependency on shaded Jackson types for key extractionDefaultJsonSerializerconfiguration (from CAMEL-22083) but refactored it into a well-documented, testable methodTest plan