davsclaus opened a new pull request, #30486:
URL: https://github.com/apache/camel/pull/30486

   [CAMEL-27289](https://issues.apache.org/jira/browse/CAMEL-27289)
   
   ## What
   
   When no transformer matched a key, 
`DefaultTransformerRegistry.resolveTransformer` took a transformer of the 
**from** data type before it lazy loaded the one of the **to** data type, and 
kept that as an alias. Only `binary`, `text` and `application-x-unchanged` are 
loaded up front (`DefaultTransformerLoader`), so an input data type such as 
`application-json`, `struct`, `java-object`, `avro-binary` or 
`protobuf-binary`, after a step that left one of those types, got the 
transformer of the previous step.
   
   Repro with Kamelets: `noop-action` (in/out `application-x-unchanged`) 
followed by `jsonin-action` (in `application-json`) and a String body `hello`:
   
   ```
   Found transformer UnchangedDataTypeTransformer for key 
application-x-unchanged/application-json using alias application-x-unchanged
   ```
   
   The body stayed the String `hello` with no Content-Type; without the noop 
action it is `"hello"` as `byte[]` with `application/json`.
   
   ## Fix
   
   The registry now lazy loads the transformer of the to data type first, and 
falls back to a transformer of the from data type only when there is none. The 
fallback is still needed, for example for a data format transformer of a scheme 
(`transformer().scheme("xml")`) that unmarshals `xml:...` into a Java type, 
where nothing is lazy loaded for the Java to type.
   
   ## Tests
   
   `DefaultTransformerRegistryTest`: a loaded transformer of the from type 
(`application-octet-stream`, `application-x-unchanged`) no longer shadows a 
lazily loadable to type (fails without the fix), and the from fallback still 
works when the to type has no transformer. The transformer, contract, data type 
and validator tests of camel-core pass (143).
   
   Blocks Kamelet batch 9a (the C1 `unchanged` defaults) and the lazy-input 
parts of 9c.
   
   _Claude Code on behalf of 
   
   🤖 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]

Reply via email to