davsclaus opened a new pull request, #3276:
URL: https://github.com/apache/camel-kamelets/pull/3276
Part of #3117: default data types on the Database, Search, Cache and NoSQL
Kamelets where the body is fixed. The Citrus tests came in #3269 and #3270;
this PR updates what they expect.
**Eight sinks get `in: json`** (`application-json`): `mariadb-sink`,
`mysql-sink`, `sqlserver-sink`, `oracle-database-sink`, `postgresql-sink`,
`solr-sink`, `elasticsearch-index-sink` and `opensearch-index-sink`.
- **The input:** before the sink, the body becomes JSON text in bytes with
`Content-Type: application/json`. The document that is stored does not change.
- **After the sink:** the SQL sinks still give a `LinkedHashMap`,
Elasticsearch and OpenSearch the document id as a `String`, and Solr a
`SimpleOrderedMap`.
- After the SQL, Elasticsearch and OpenSearch sinks, `Content-Type` is now
`application/json`, even when the body is the id of the document. The Solr
template removes it, as before.
- **New inputs:** a `Map` or a `List` is now written as JSON first, so these
sinks accept it. Text that is not a JSON object or array becomes a JSON string.
The SQL sinks then find no fields in it, and before they failed at the JSON
parse.
- **Descriptions:** the seven SQL, Elasticsearch and OpenSearch sinks now
say that `Content-Type` is set to `application/json`.
### No default, and why
- **The sources**, all of them, because of the Camel bug noted on #3117 and
in #3275: a source's `out` data type runs after the consuming route. I tried
`out: json` on `mongodb-source`, and the next step still got
`InputStreamCache`. Each source also has a reason of its own:
- `mongodb-changes-stream-source` can give the JSON literal `null`.
- `couchbase-source` gives an SDK object.
- `infinispan-source` has no body.
- `redis-source` gives text whose type depends on `serializer`.
- **`mongodb-sink`:** with `in: json`, the insert fails on `byte[]`
(`ClassCastException: class [B cannot be cast to class [Ljava.lang.Object;`),
from `MongoDbProducer.createDoInsert()` in camel-mongodb. That is a Camel bug.
It also means `mongodb-sink` fails today on `byte[]` input, for example from
`kafka-source`.
- **`couchbase-sink`:** text that is not JSON would be stored as a binary
document instead of a JSON string.
- **`redis-sink`, `infinispan-sink`:** they store any body as the value.
- **`cassandra-sink`:** with `jsonPayload: false` the body is used as it is.
### Found along the way
- **`mongo/mongodb-sink-route.citrus.it.yaml` only checks a log line written
before the Kamelet runs**, so it passed while the insert threw.
`postgresql-sink`'s test now checks the body type, `Content-Type` and update
count after the sink. The mongo tests are left for a follow-up.
### Upgrade note
For #3190, under the data types, when this is merged:
- The SQL, Solr, Elasticsearch and OpenSearch sinks turn their input into
JSON bytes and set `Content-Type: application/json`. They now also accept a
`Map` or a `List`.
- After the SQL, Elasticsearch and OpenSearch sinks, `Content-Type` is
`application/json`.
### Tests
- **Citrus:** `DatabaseIT`, `PostgresIT` and `SearchIT`: 14 of 14 pass.
- **Build:** `./mvnw clean install` from the root passes, run twice.
_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]