davsclaus opened a new pull request, #95:
URL: https://github.com/apache/camel-jbang-examples/pull/95

   Four examples look up one SKU in `stock.json`: `connect/stock-api`, 
`connect/http-client`, `contracts/openapi-server` and `ai/mcp-server`. They did 
it with a JsonPath filter, `$[?(@.sku == '${header.sku}')]` with `resultType: 
java.util.List`, then checked the size and took `${body[0]}`.
   
   They now unmarshal the file and find the item with one line of Groovy:
   
   ```yaml
   - unmarshal:
       json:
         library: Jackson
   - setBody:
       expression:
         groovy:
           expression: "body.find { it.sku == headers.sku }"
   ```
   
   That gives the item as a map, or null, so the choice checks `${body} == 
null` and the `${body[0]}` step goes. Groovy reads more plainly than the filter 
syntax, and models write it well. In local-model benchmark runs the model 
repeatedly dropped the size-check-and-unwrap step after the JsonPath filter.
   
   READMEs, the `teaches` metadata and `camel-jbang-example-catalog.json` 
(regenerated) are updated to match. `transform/json-transform` keeps JsonPath 
because it teaches jsonpath and jq. The connect-service examples only read 
single fields (`$.orderId`) and are unchanged.
   
   Tested:
   - `camel test run` passes for all four examples on 4.23.0-SNAPSHOT
   - `connect/stock-api` on `--camel-version=4.22.1`: `curl /stock/CAMEL-MUG` 
returns 200 with the item, `/stock/CAMEL-SOCKS` returns 404 with `unknown sku 
CAMEL-SOCKS`
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m


-- 
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