davsclaus opened a new pull request, #29192: URL: https://github.com/apache/camel/pull/29192
# Description JIRA: [CAMEL-25922](https://issues.apache.org/jira/browse/CAMEL-25922) ## What is wrong The resolved value of a placeholder is parsed again for nested placeholders. If that value contains `}}` but no `{{`, the parser fails with `Missing {{ from the text`. JSON that ends with a nested object (`{"a":{"b":1}}`) or with a Simple expression (`{"title":${header.title}}`) always ends with `}}`, so passing such a value as a route template or Kamelet parameter, or putting it in a property, fails: ``` FailedToCreateRouteException: Failed to create route: templated at: >>> SetBody[simple{{{expression}}}] <<< ... Caused by: IllegalArgumentException: Missing {{ from the text: {"title":${header.title}} ``` The same text written directly in a route works, because text without `{{` is not parsed at all. ## The fix `DefaultPropertiesParser.doParseNested` returns a resolved value unchanged when it has no `{{` that can start a placeholder (one that is not escaped or quoted). Such a value has no placeholders, so before this change the parser either returned it unchanged or failed on a `}}`. Now it is never an error, which is how text at the top level is already handled. What is unchanged: - A value that contains real placeholders and also a stray `}}` still fails. `?nested=false` or escaping still covers that. - A value such as `{{"a":1}}` is still the placeholder `"a"` with default value `1`, as it is valid placeholder syntax. ## Prior decision This was first reported as CAMEL-18576 (2022, Kamelet with an Elasticsearch query). Two options were proposed there: `{{myKey?nested=false}}`, and to "relax the {{ }} check on level 2+ since its the value of the placeholder that cannot always be assumed to be another placeholder". The ticket settled for turning nested off globally, escaping and `?nested=false` "for now". This PR is the second option. All three workarounds keep working. `ExpressionPlaceholderNestedTest.testPlaceholderOn`, added by CAMEL-18576, asserted that this JSON fails with nested placeholders on. It now asserts that the JSON comes through. ## Docs The "Turning off nested placeholders" and "Escaping a property placeholder" sections of `using-propertyplaceholder.adoc` used `{"query":{"match_all":{}}}` as the example that needs a workaround, which now just works. Their examples now use a value with `{{` that is not a Camel placeholder (`Hello {{name}}`), which still needs `?nested=false` or escaping. ## Tests - New `PropertiesComponentNestedJsonValueTest`: JSON property values, a property that refers to one, JSON mixed with a placeholder, the route template from the JIRA, and the `?nested=false` and escaping examples from the docs. Without the fix the JSON and route template tests fail with the error from the JIRA. - The whole camel-core test suite passes (8849 tests, 44 skipped). _Claude Code on behalf of Claus Ibsen_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0128ThHB3iQdrvSRLVBGRrdP -- 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]
