Fix #462: document that replace-field-action only renames top level fields - #2995
Merged
Conversation
…evel fields
The Kamelet delegates to org.apache.camel.component.kafka.transform.ReplaceField,
whose process() iterates the top level map only:
for (Map.Entry<Object, Object> entry : body.entrySet()) {
final String fieldName = (String) entry.getKey();
if (filterNames(fieldName, enabledFields, disabledFields)) {
final Object fieldValue = entry.getValue();
updatedBody.put(renameOptional(fieldName, renamingMap), fieldValue);
}
}
Nested objects are carried across as opaque values and never descended into,
so naming a nested field is silently a no-op. Reproduced with the example
from the issue:
renames=message:msg {"message":{"Hola":"mundo"}} -> {"msg":{"Hola":"mundo"}}
renames=Hola:Hi {"message":{"Hola":"mundo"}} -> {"message":{"Hola":"mundo"}}
Supporting nested paths would be a change to camel-kafka, not to this
template, so this documents the actual contract instead of implying a
capability the Kamelet does not have. enabled and disabled filter on the
same top level keys and are worded to match.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #462.
The report is accurate and still reproduces four years on. This documents the real contract rather than implying a capability the Kamelet does not have — the behaviour itself is not ours to change.
Reproduced
Using the exact example from the issue, through the shipped Kamelet:
renamesmessage:msg(top level){"message":{"Hola":"mundo"}}{"msg":{"Hola":"mundo"}}Hola:Hi(nested){"message":{"Hola":"mundo"}}{"message":{"Hola":"mundo"}}The nested rename is a silent no-op — no error, no warning, body unchanged.
Why
replace-field-actionis a thin wrapper aroundorg.apache.camel.component.kafka.transform.ReplaceField. Itsprocess()walks the top level map and nothing else:A nested object arrives as
fieldValueand is put back untouched — the transform never descends into it.enabledanddisabledfilter on the same top level keys viafilterNames, so the limitation applies to all three properties, not justrenames.Scope
Supporting nested paths means changing
camel-kafka, not this template — per the contributor guidelines that isapache/camelterritory. It would also be a semantic extension rather than a bug fix: the transform mirrors the Kafka ConnectReplaceFieldSMT, which is likewise top level only.So this PR makes the documented contract match the implemented one:
plus the same clarification on
renames,enabledanddisabled.That is deliberately modest. The reason this issue stayed open for four years is that nothing told the user the limitation existed — the property descriptions read as though any field could be renamed. Saying so up front is the part that actually prevents recurrence.
Verification
script/validatorreports no errors,script/generatorproduces no doc changes beyond the regeneratednav.adoc(unchanged here), andmvn clean installpasses from the repository root. No template or behavioural change — descriptions only.Note for reviewers
If you would rather have nested support than a documented limitation, the right move is an issue against
apache/camelforReplaceField, and I am happy to open it and reference this. I did not assume that, because changing the transform would also change behaviour for every existing user of the SMT-compatible semantics.I checked the sibling transforms (
DropField,HoistField,MaskField,ValueToKey) to see whether they share the limitation, but my check was inconclusive and I have not claimed anything about them here. Worth a look separately if this wording is agreed.Claude Code on behalf of Andrea Cosentino