Skip to content

CAMEL-24064: Fix module registration in jackson3 type converter and wrap JacksonException in data type transformers#24705

Open
Croway wants to merge 1 commit into
apache:mainfrom
Croway:CAMEL-24064-jackson3-module-registration-and-exception-wrapping
Open

CAMEL-24064: Fix module registration in jackson3 type converter and wrap JacksonException in data type transformers#24705
Croway wants to merge 1 commit into
apache:mainfrom
Croway:CAMEL-24064-jackson3-module-registration-and-exception-wrapping

Conversation

@Croway

@Croway Croway commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Fixes two regressions in camel-jackson3 from the Jackson 2 → Jackson 3 port (CAMEL-22857):

  1. Type converter drops all but the last configured Jackson moduleJacksonTypeConverters.resolveObjectMapper() replaced the mapper with a fresh JsonMapper.builder().addModule(module).build() on every loop iteration over CamelJacksonTypeConverterModuleClassNames, so only the last module was registered. Now all modules are accumulated on a single builder (matching the Jackson 2 behavior of registerModule).

  2. Jackson exceptions escape data type transformers unwrappedJsonStructDataTypeTransformer and JsonPojoDataTypeTransformer still caught the checked IOException that Jackson 3 read/write calls no longer throw, so malformed JSON escaped as a raw unchecked JacksonException instead of being wrapped in CamelExecutionException with the exchange attached (as JsonDataTypeTransformer already does). Added JacksonException to the catch clauses.

Each new test was verified to fail against the unfixed code and pass with the fix; the full camel-jackson3 suite passes (103 tests).

Note: camel-jackson3 was introduced in 4.19.0, so no backport to camel-4.18.x is applicable.

JIRA: https://issues.apache.org/jira/browse/CAMEL-24064

Claude Code on behalf of Croway

…rap JacksonException in data type transformers
@Croway Croway requested review from davsclaus and gzurowski July 15, 2026 08:31
@Croway Croway added the bug Something isn't working label Jul 15, 2026

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clean, well-targeted fix for two genuine regressions in the Jackson 2 → Jackson 3 port.

Module registration fix (JacksonTypeConverters.java): The broken code called JsonMapper.builder().addModule(module).build() inside the loop, creating a fresh mapper per iteration and discarding previously registered modules. The fix correctly accumulates modules on a single JsonMapper.Builder instance before calling build() once — matches the Jackson 3 idiomatic pattern.

JacksonException wrapping (JsonPojoDataTypeTransformer / JsonStructDataTypeTransformer): In Jackson 3, JacksonException extends RuntimeException (not IOException as in Jackson 2), so the existing IOException catch clauses missed Jackson parse errors. The added JacksonException catches are correct and consistent with how JsonDataTypeTransformer (the third transformer in the same package) already handles it.

Test coverage is solid — the multi-module test verifies both custom modules are active, and the malformed-JSON tests confirm CamelExecutionException wrapping.

Minor observation (non-blocking): the IOException catch in JsonPojoDataTypeTransformer is now only reachable via getBodyAsStream() I/O errors, not Jackson parse errors. This is technically correct but could be clarified with a comment in a future cleanup.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of @gnodet

gnodet added a commit to gnodet/camel that referenced this pull request Jul 15, 2026

@oscerd oscerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Federico — both fixes look correct, and I like that each is backed by a test that fails before / passes after.

Fix 1 — module registration (JacksonTypeConverters): good catch. The old loop rebuilt the mapper on every iteration (mapper = JsonMapper.builder().addModule(module).build();), so only the last discovered module actually survived. Hoisting a single JsonMapper.Builder and calling build() once restores the Jackson-2 registerModule semantics, and JacksonConversionsMultipleModulesTest (Foo + Bar) is exactly the test that would have caught the regression.

Fix 2 — JacksonException in the transformers: correct. In Jackson 3, tools.jackson.core.JacksonException extends RuntimeException (vs Jackson 2's JsonProcessingException extends IOException), so malformed JSON was slipping past the checked-only catch. Adding it to the multi-catch and wrapping in CamelExecutionException(..., exchange, e) preserves the original cause and matches the sibling JsonDataTypeTransformer.

One trivial, non-blocking nit: JsonPojoDataTypeTransformer keeps IOException in its catch list while JsonStructDataTypeTransformer doesn't — for the Jackson read path it's now effectively dead (only kept legal by getJavaObject's throws IOException). Harmless; could drop it for symmetry, but not worth a revision on its own.

A couple of CI checks are still running as I write this — worth letting it go fully green before merge, but the code itself looks good.


Reviewed with Claude Code on behalf of Andrea Cosentino (@oscerd). This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.

@github-actions

Copy link
Copy Markdown
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 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.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-jackson3

🔬 Scalpel shadow comparison — Scalpel: 11 tested, 29 compile-only — current: 11 all tested

Maveniverse Scalpel detected 40 affected modules (current approach: 11).

⚠️ Modules only in Scalpel (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

Skip-tests mode would test 11 modules (1 direct + 10 downstream), skip tests for 29 (generated code, meta-modules)

Modules Scalpel would test (11)
  • camel-jackson3
  • camel-jackson3-avro
  • camel-jackson3-protobuf
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
Modules with tests skipped (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (40 modules)
  • Camel :: All Components Sync point
  • Camel :: Assembly
  • Camel :: Catalog :: CSimple Maven Plugin (deprecated)
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Catalog :: Camel Report Maven Plugin
  • Camel :: Catalog :: Camel Route Parser
  • Camel :: Catalog :: Console
  • Camel :: Catalog :: Dummy Component
  • Camel :: Catalog :: Lucene (deprecated)
  • Camel :: Catalog :: Maven
  • Camel :: Catalog :: Suggest
  • Camel :: Component DSL
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: Endpoint DSL
  • Camel :: Endpoint DSL :: Support
  • Camel :: Integration Tests
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Jackson 3
  • Camel :: Jackson 3 Avro
  • Camel :: Jackson 3 Protobuf
  • Camel :: Kamelet Main
  • Camel :: Launcher
  • Camel :: Launcher :: Container
  • Camel :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

gnodet added a commit to gnodet/camel that referenced this pull request Jul 15, 2026
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.

4 participants