davsclaus opened a new pull request, #3253:
URL: https://github.com/apache/camel-kamelets/pull/3253
Fixes #3088.
`extract-field-action` gave a text field as JSON text by default, so
`{"orderId":"ORD-1"}` became `"ORD-1"` with its quotes, and a comparison on the
value failed. `trimField: true` removed the quotes, but then gave an object or
an array field as a Java `Map` or `List` that was still labelled
`application/json`.
Now the type of the value decides, not a flag and not the `Content-Type` of
the incoming message:
| Field value | Before (default) | Now |
|---|---|---|
| text `"ORD-1"` | `"ORD-1"`, `application/json` | `ORD-1`, `text/plain` |
| number `3`, boolean `true` | `3`, `true`, `application/json` | `3`,
`true`, `text/plain` |
| object `{"name":"Ann"}` | `{"name":"Ann"}`, `application/json` | the same |
| array `["a","b"]` | `["a","b"]`, `application/json` | the same |
| missing, or `null` | `null`, `application/json` | empty body, no
`Content-Type` |
The body is always a `String`. Before, without `Content-Type:
application/json`, the value was the Java object itself (a `Map` for an
object); now it is the same as with it.
With `headerOutput: true`, the header still gets the value as it is in the
JSON (a `String`, a number, a `Map`…). The body and its `Content-Type` are now
left exactly as they were. Before, with `Content-Type: application/json`, the
body was parsed and written again. `strictHeaderCheck` works as before.
**`trimField` is deprecated and ignored** (`deprecated: true`). It is still
passed to the `ExtractField` bean, which only sets an exchange property that
the template removes, so a configuration that sets it still starts. The
validator does not accept an option that the template does not use.
This changes behaviour, as decided for the 4.24 overhaul. I'll add a note to
#3190 and apache/camel#30331.
### Tests
- Citrus `extract-field-action-route-test`: now expects `Camel rocks!`
without quotes, and `Content-Type: text/plain`. Its timer now fires once
(`repeatCount: 1`) instead of every 10 seconds, so it cannot send again while
the test stops.
- New Citrus `extract-field-action-object-route-test`: an object field
arrives as `{"name":"Ann","vip":true}` with `Content-Type: application/json`.
- `mvn verify -Dtest=CommonIT#transformation`: 8 tests, 0 failures.
- With `camel run`, I checked text, number, boolean, decimal, object and
array fields, a missing and a `null` field, with and without `Content-Type:
application/json`, `headerOutput` with a text and an object value,
`strictHeaderCheck` with an existing header, `trimField: true` and `false`, and
a `Map` body. Each gave the result in the table above.
- `./mvnw clean install` passes and regenerated the library copy and the
index.
_Claude Code on behalf of Claus Ibsen_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]