davsclaus opened a new pull request, #28939:
URL: https://github.com/apache/camel/pull/28939

   Fixes [CAMEL-26163](https://issues.apache.org/jira/browse/CAMEL-26163).
   
   ### What was wrong
   
   `WordpressPostProducer` and `WordpressUserProducer` read the body with 
`getBody(Post.class)` / `getBody(User.class)` to create or update a post or 
user. There is no type converter from JSON text or a `Map` to these classes, so 
the body became `null`. The service then failed with `NullPointerException: 
Please define an object to create` (or `update`), which does not say the body 
type is wrong.
   
   ### What changed
   
   - `AbstractWordpressProducer` has a new `getMandatoryBody(exchange, type)`:
     - a `Post` / `User` body is used as is;
     - a `Map` body is converted with Jackson (`ObjectMapper.convertValue`);
     - JSON text (`String`, `byte[]` or `InputStream`) is read with Jackson 
(`ObjectMapper.readValue`);
     - any other body, or JSON that cannot be read, fails with an 
`InvalidPayloadException` that names the type.
   - The CXF client already writes and reads these classes with a default 
Jackson `ObjectMapper` (`JacksonJsonProvider`), so the field names are the same 
as in the WordPress answers (for example `first_name`). The conversion targets 
a fixed class, with no polymorphic typing.
   - The insert and update methods of both producers use it. A delete does not 
read the body, so it is unchanged.
   - Small fix on the same lines: the debug log `Trying to create a new user{}` 
was missing a space.
   
   ### Tests
   
   - `WordpressPostOperationTest`: insert from JSON text, insert from JSON 
`byte[]`, update from a `Map`, and an `Integer` body / invalid JSON fail with 
`InvalidPayloadException`.
   - `WordpressUserOperationTest`: insert from JSON text, update from a `Map`, 
and an `Integer` body fails with `InvalidPayloadException`.
   - The mock server's `WordpressServerHttpRequestHandler` now keeps the last 
request body, so the tests check that the converted fields reach WordPress.
   - All 7 new tests fail without the fix (NPE, or the wrong exception type). 
The module suite passes: 28 tests, 0 failures (`mvn clean install 
-Psourcecheck`).
   
   ### Docs and generated files
   
   - `@BodyTypes` `producerIn`: the carriers are now `pojo, text, bytes, 
stream, map`, and the description no longer says that JSON text or a Map fails. 
The regenerated `wordpress.json` is copied to `camel-catalog`.
   - `wordpress-component.adoc` (and its catalog copy): one paragraph on JSON 
text and Map bodies in "Producer Example".
   - No upgrade guide entry: before, these bodies failed with an NPE, so nobody 
can rely on the old behaviour.
   
   ### Not changed
   
   - No global type converter from String/Map to `Post` / `User` was added; the 
conversion stays inside the producer.
   - `AbstractWordpressCrudServiceAdapter` keeps its `Objects.requireNonNull` 
checks; the producer now fails earlier with a clearer error.
   
   _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]

Reply via email to