davsclaus opened a new pull request, #29003: URL: https://github.com/apache/camel/pull/29003
Fixes [CAMEL-26175](https://issues.apache.org/jira/browse/CAMEL-26175). ### 1. A byte array body for CREATE and UPDATE was sent as a JSON array of numbers `ODataHelper.toJson` passed every body that is not a String to `Jsoner.serialize`, so a `byte[]` with JSON text was sent as `[123,34,...]`. Now a byte array, an `InputStream`, a `Reader`, a `StreamCache`, a `File`, a `Path` or a `WrappedFile` is converted to a String with the type converter and sent as it is, like a String body. A `Map` or a `List` is still serialized with Jsoner. ### 2. An InputStream or File body failed Same cause: `Jsoner.serialize` threw `... isn't JSON serializable`. Fixed by the change in 1. ### 3. A null body sent an empty POST or PATCH CREATE and UPDATE now fail with an `IllegalArgumentException` when the body is null or empty (also an empty String, byte array or stream), and no request is sent. The message says to set the body to `{}` to send an empty JSON object. ### 4. A JSON response that is not an object failed `parseJsonObject` threw `Expected an OData JSON object response` for a JSON array or a plain value. It is replaced by `ODataHelper.parseJson`, which returns what Jsoner parses: a JSON array is the body as a `List` (a `JsonArray`), a plain value as a number, a String or a boolean. The count, next link and `@odata.etag` are read only from a JSON object; the HTTP `ETag` header is still mapped for any response. ### 5. The catalog showed no default for `operation` Added `defaultValue = "READ_SET"` to the `@UriParam`. ### Tests 7 new tests in `ODataProducerTest` (WireMock): CREATE with a byte array and a stream body, UPDATE with a file body, CREATE with a null body and UPDATE with an empty byte array (both fail and send no request), a JSON array response and a plain value response. All 7 failed before the fix (wrong request body/404, `isn't JSON serializable`, an HTTP error instead of the clear failure, `Expected an OData JSON object response`). The module suite passes: 47 tests. ### Docs and generated files - `@BodyTypes` of the endpoint: CREATE/UPDATE take text, bytes, a stream, a file, a map or a list; the response can be a map, a list, a value, text or null. Descriptions updated. - Component doc: new "Message Body" section, and the response section says what a non-object response gives. - Regenerated `odata.json`, the catalog copies (json and adoc) and `ODataEndpointBuilderFactory` (`Default: READ_SET`). - Upgrade guide 4.24: new `camel-odata` section (bytes/stream/file bodies, empty body now fails, non-object response). ### Not changed - A POJO body still fails: the module has no Jackson; marshal it to JSON first (said in the doc). - A response that is not JSON at all (for example XML or raw text of `$value`) still fails to parse. That is a separate question (whether to look at the response Content-Type). ### Open question Failing on an empty body (3) changes behaviour for anyone who used CREATE to call an OData action without parameters with no body. They can send `{}` instead; the upgrade guide says so. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 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]
