davsclaus opened a new pull request, #28435: URL: https://github.com/apache/camel/pull/28435
JIRA: https://issues.apache.org/jira/browse/CAMEL-25928 **Stacked on #28424** (the EIP body types): this PR targets its branch, and moves to `main` once #28424 is merged. ## What Many expression languages have a `resultType` option, and when it is set the result is converted to that class, so the body is known. Until now the catalog said `unknown` for simple, groovy, jsonpath and the other script languages, and the 8 languages that mentioned `resultType` only listed it in `dependsOn`: "not known when resultType is set". This PR lets a body type name the option that gives its class. - `@BodyType` gets a new member, `javaTypeOption`. When that option is set, the body is an object of the class it names, or null when the value does not convert. That holds whatever the carriers and the other options say. - The carrier follows the class, and `BodyTypeModel.carrierOf(String)` gives it. Short names Camel takes, such as `String` and `int`, work too. | Class | Carrier | | --- | --- | | `String` | `text` | | `byte[]` | `bytes` | | `InputStream` or `Reader` | `stream` | | `File` or `Path` | `file` | | a number, boolean or character | `value` | | `Map` | `map` | | a `Collection` or an array | `list` | | `Iterator` | `iterator` | | any other class | `pojo` | - **21 languages** declare `javaTypeOption = "resultType"` on `expressionOut`: bean, constant, datasonnet, file, groovy, hl7terser, jactl, java, jq, js, jsonpath, mvel, ognl, python, python3, quickjs, ref, simple, spel, xpath and xquery. `resultType` is no longer in their `dependsOn`. - setBody and transform take their body from `expressionOut` (#28424), so `setBody` with `simple` and `resultType: java.lang.Integer` is now a known value, and the EIPs need no change. - tokenize and xtokenize are left out: with `resultType` they still return an iterator, and only its elements are converted. - **convertBodyTo** declares `javaTypeOption = "type"` instead of the hand-written list of common types (String, byte[], InputStream, Map and List) that #28424 had. - **The script EIP** is unchanged. It evaluates its expression but does not use the result (`ScriptProcessor` discards it), so a `resultType` on its expression says nothing about the body. Its `eipOut` stays `unknown`, because the script itself can set the body. ## Checked at build time `javaTypeOption` must: - be an option of the model; - be on a body after a step only; - not be in `dependsOn` or `byOption` of the same side; - not be on a side with `from`. ## Shown in - The **Message Body** section of the doc pages: "With `resultType` set: an object of the class it names, or null." - `camel catalog doc` and the MCP `camel_catalog_doc` tool. - The catalog page (`camel-catalog.adoc`) documents the new member and the carriers of the classes. ## Checked at runtime To confirm the rule, I read how each language applies `resultType`: - most convert through `ExpressionBuilder.convertToExpression`; - bean, jsonpath, joor and xpath convert with the type converter; - xquery takes String, Collection or Node and fails on another class. The new `EipBodyTypesTest.theResultTypeOfTheLanguage` runs the following and checks that each body is an instance of the class: - setBody with simple and an Integer `resultType`; - transform with simple and `byte[]`; - setBody with constant and Long. `convertBodyToTheTypeOption` does the same for convertBodyTo. ## Not in this PR - **The YAML validator** does not read the body types of languages or EIPs yet. That is the next step of the plan on CAMEL-25928, and it will use `javaTypeOption` there. - **Data formats and components** with an option that names the class of the body, such as `unmarshalType` of jackson or `outputClass` of sql, are candidates for `javaTypeOption`. Each needs a check of how the option combines with the others (for example `useList`), so they come later. ## Tests - **camel-package-maven-plugin:** `BodyTypesHelperJavaTypeOptionTest` (5 tests). - **camel-tooling-model:** - `JsonMapperTest.testShouldReadAndWriteJavaTypeOption`; - `testCarrierOfJavaType`. - **camel-core:** - `EipBodyTypesTest.theResultTypeOfTheLanguage`; - `convertBodyToTheTypeOption`. - **camel-jbang-core:** `CatalogDocsTest` covers the line for simple, xpath and convertBodyTo. - **Local full check:** tooling, the changed modules, regeneration drift, the catalog tests, the YAML DSL and DSL regeneration, and the validator and camel-jbang-core tests. _Claude Code on behalf of davsclaus_ 🤖 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]
