Claus Ibsen created CAMEL-27289:
-----------------------------------
Summary: camel-core - the transformer registry uses the
transformer of the from data type when the transformer of the to data type is
not loaded yet
Key: CAMEL-27289
URL: https://issues.apache.org/jira/browse/CAMEL-27289
Project: Camel
Issue Type: Bug
Components: camel-core
Reporter: Claus Ibsen
Fix For: 4.24.0
{{DefaultTransformerRegistry.resolveTransformer(key)}} tries, in order: the
exact key, the scheme wildcards, {{TransformerKey(to)}}, then
{{TransformerKey(from)}}, and only then lazy-loads the transformer of the
{{to}} data type. The match is cached as an alias.
Only {{application-octet-stream}}, {{text-plain}} and
{{application-x-unchanged}} are registered at startup
({{DefaultTransformerLoader}}). {{application-json}}, {{application-x-struct}},
{{application-x-java-object}}, {{avro-binary}}, {{protobuf-binary}} and the
cloudevents types are lazy-loaded. So when a message whose data type has a
registered transformer goes into a data type whose transformer was not used
yet, the transformer of the *from* type is used, and the to transformer never
runs, for this and every later message.
Reproduced with {{camel run}} on 4.24.0-SNAPSHOT (main with CAMEL-27269): an
action Kamelet with {{dataTypes.in/out.default}} {{application-x-unchanged}},
followed by an action Kamelet with {{dataTypes.in.default}}
{{application-json}}, on a String body {{hello}}:
{noformat}
Found transformer UnchangedDataTypeTransformer for key
application-x-unchanged/application-json using alias application-x-unchanged
jsonin got [hello] class=java.lang.String ct=
{noformat}
Without the first Kamelet, the json transformer is lazy-loaded and the body is
{{"hello"}} as {{byte[]}} with {{Content-Type: application/json}}. The same
happens after any Kamelet whose out type is loaded, for example an
{{application-x-struct}} out followed by a {{application-json}} or
{{text-plain}} in (seen with json-deserialize-action → value-to-key-action in
the Kamelet catalog).
Expected: when no transformer matches the key, the transformer of the {{to}}
data type is lazy-loaded before falling back to the transformer of the {{from}}
data type (or the from fallback is dropped for data type transformers), so the
in data type of a Kamelet always runs its own transformer.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)