davsclaus opened a new pull request, #29759: URL: https://github.com/apache/camel/pull/29759
Fixes [CAMEL-26000](https://issues.apache.org/jira/browse/CAMEL-26000) The jsonApi data format handled only documents whose primary data is one resource object. A collection document, whose `data` is an array (for example the answer to `GET /books`), failed both ways: - unmarshal: `InvalidJsonApiResourceException: Primary data must be either a single resource object, ...` - marshal of a List: `DocumentSerializationException` (`ClassCastException: ArrayNode cannot be cast to ObjectNode`) **Change** (`JsonApiDataFormat`) - Unmarshal reads the body once as bytes and looks at the top level `data` member with a Jackson 2 streaming parser (only the tokens before `data` are read, other members are skipped). When it is an array, the document is read with `readDocumentCollection` and the body is a `List` of `mainFormatType` objects; otherwise `readDocument` as before. Input that is not a JSON object goes to `readDocument`, so its error is unchanged. - Marshal writes a `Collection` or an array body with `writeDocumentCollection`; any other body as one resource object, as before. - jsonapi-converter uses Jackson 2, which came in transitively; `jackson-core` (`${jackson2-version}`) is now declared, since the data format uses its parser directly. - `@BodyTypes` (marshalIn and unmarshalOut now include `list`), the data format page (new "Collection documents" section) and the catalog copies are updated. No upgrade note: both cases failed before, single resources behave as before. **Tests** (`JsonApiDataFormatTest`, 14 pass; the 6 collection tests added first failed with the exceptions above) - unmarshal of an array document → List of `MyBook`, also with `meta` / `links` before `data` (and a nested `data` inside `meta`) - unmarshal of `{"data":[]}` → empty List - marshal of a List and of an array → array document; marshal of an empty List → `{"data":[]}` - round trip of a List, relationships included - the existing single-resource tests are unchanged _Claude Code on behalf of 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]
