chore: find the SKU in stock.json with Groovy instead of a jsonpath filter - #95
Merged
Merged
Conversation
…ilter
stock-api, http-client, openapi-server and mcp-server looked up one SKU with
a jsonpath filter returning a list, then a size check and ${body[0]}. They now
unmarshal the file and run body.find { it.sku == headers.sku }, which gives
the item or null in one line. READMEs, metadata and the catalog follow.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
davsclaus
added a commit
to apache/camel
that referenced
this pull request
Oct 2, 2026
…ovy instead of a jsonpath filter Synced with the sync-example-catalog profile after apache/camel-jbang-examples#95: stock-api, http-client and openapi-server unmarshal stock.json and find the SKU with body.find { it.sku == headers.sku }, the item or null. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
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.
Four examples look up one SKU in
stock.json:connect/stock-api,connect/http-client,contracts/openapi-serverandai/mcp-server. They did it with a JsonPath filter,$[?(@.sku == '${header.sku}')]withresultType: 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:
That gives the item as a map, or null, so the choice checks
${body} == nulland 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
teachesmetadata andcamel-jbang-example-catalog.json(regenerated) are updated to match.transform/json-transformkeeps JsonPath because it teaches jsonpath and jq. The connect-service examples only read single fields ($.orderId) and are unchanged.Tested:
camel test runpasses for all four examples on 4.23.0-SNAPSHOTconnect/stock-apion--camel-version=4.22.1:curl /stock/CAMEL-MUGreturns 200 with the item,/stock/CAMEL-SOCKSreturns 404 withunknown sku CAMEL-SOCKS🤖 Generated with Claude Code
https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m