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

   [CAMEL-25329](https://issues.apache.org/jira/browse/CAMEL-25329)
   
   **The problem:** `marshal: json` (Jackson) treated every body as an object 
to serialize. When the body already is the JSON text, the result was wrong in 
four ways:
   
   | Body | Before | Now |
   |---|---|---|
   | `String` holding `{"sku": "CAMEL-MUG"}` | double-encoded: `"{\"sku\": 
\"CAMEL-MUG\"}"` | written as-is |
   | `byte[]` of that JSON | Base64: `"eyJza3UiOi..."` | written as-is |
   | `InputStream` / stream cache | fails: `No serializer found for class 
...ByteArrayInputStreamCache` | written as-is |
   | file body (`GenericFile`) | fails: `No serializer found for class 
...FileBinding` | written as-is |
   | any other `String` (`hello`) | `"hello"` | unchanged |
   | POJO, Map, List | marshalled | unchanged |
   
   A file, a stream or bytes are the serialized form of a payload, never an 
object to serialize. A String holding a JSON object or array is that same text, 
so `marshal` has nothing to do for them.
   
   **The change:**
   - The JSON `JacksonDataFormat` of **camel-jackson** and **camel-jackson3** 
(and so `ListJacksonDataFormat`) overrides `marshal` and writes such a body 
as-is.
   - The Content-Type header is set as for any marshal.
   - There is no parsing: the decision is the type, and for a String its first 
and last non-blank character.
   - The change is not in `AbstractJacksonDataFormat`, because the binary Avro 
data format extends it too.
   - An upgrade-guide note for 4.23 covers the String case, and the data format 
pages describe the new behaviour.
   
   **Why:** in the local-model benchmark (round 4, contracts/openapi-server), 
routes built the answer as JSON text with Simple and then added `marshal: 
json`. That double-encoded the answer in 3 of 10 steps. A WARN-only variant 
tested overnight already took it to 0 (step 2 from 2/5 to 5/5, final state 
14/20 to 18/20). This change makes those routes simply work.
   
   **Tests:**
   - New `JacksonMarshalJsonTextTest` in both modules, covering:
     - a JSON object, array and padded text String
     - a non-JSON String
     - bytes, a stream and a file
     - a Map unchanged
   - Suites: camel-jackson 106 tests, camel-jackson3 116 tests, all pass.
   - Checked live with `camel run`: String, byte[], InputStream and a file all 
give the JSON unchanged.
   
   Gson, JSON-B and Fastjson behave like Jackson did before. They can follow if 
wanted.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
   


-- 
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