davsclaus opened a new pull request, #30494: URL: https://github.com/apache/camel/pull/30494
## What [CAMEL-27301](https://issues.apache.org/jira/browse/CAMEL-27301): the `JsonNode` type converters of camel-jackson3 and camel-jackson work without an exchange. A type converter can be called without an exchange. The simple language does that for `${body[field]}`, so `${body[name]}` on an `ObjectNode` body failed with a `NullPointerException` in `JacksonTypeConverters.toMap`, which called `exchange.getContext()`. ## Changes - Both modules had the same code in every `JsonNode` converter (`toJsonNode` from String, byte[], InputStream, File, Reader and Map; `toString`, `toByteArray`, `toInputStream`, `toReader`, `toMap`), so all of them are fixed, not only `toMap`. - `JacksonTypeConverters` is now `CamelContextAware`. The generated loader already calls `CamelContextAware.trySetCamelContext` on the converter instance, as for `ReactiveStreamsConverter`. Without an exchange, the converter resolves the `ObjectMapper` from that context: the single `ObjectMapper` in the registry, or else the default `ObjectMapper`. This is what `resolveObjectMapper` does with an exchange. When there is no context at all (a converter created by hand), it uses the default `ObjectMapper`. - The fallback converter (`convertTo`) is unchanged: without an exchange it still returns `null`, as before. ## Tests - New tests in `JacksonJSonNodeConverterTest` (both modules): `jsonNodeToMapWithoutExchange`, `convertWithoutExchange`, and `simpleBodyFieldOfObjectNode` (`${body[name]}` on an `ObjectNode`). Without the fix, all three fail in camel-jackson3 with the `NullPointerException` from the JIRA. - `camel-jackson`: 127 tests, `camel-jackson3`: 133 tests, all pass. _Claude Code on behalf of Claus Ibsen_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
