[ 
https://issues.apache.org/jira/browse/CAMEL-25329?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-25329.
---------------------------------
    Fix Version/s: 4.23.0
       Resolution: Fixed

Fixed on main via https://github.com/apache/camel/pull/27350

> JSON data formats - marshal json writes a body that is already JSON text 
> (file, stream, bytes, JSON String) as-is
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25329
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25329
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-gson, camel-jackson
>            Reporter: Claus Ibsen
>            Priority: Major
>             Fix For: 4.23.0
>
>
> {{marshal: json}} (Jackson) treats every body as an object to serialize. When 
> the body is already the JSON text, the result is wrong in four ways (checked 
> on 4.23.0-SNAPSHOT):
> ||Body||Today||
> |String holding {"sku": "CAMEL-MUG"}|double-encoded: "{\"sku\": 
> \"CAMEL-MUG\"}"|
> |byte[] of that JSON|base64: "eyJza3UiOi..."|
> |InputStream / stream cache|fails: No serializer found for class 
> ...ByteArrayInputStreamCache|
> |file body (GenericFile)|fails: No serializer found for class ...FileBinding|
> 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 the same 
> text. marshal json has nothing to do for them.
> *Proposal:* the JSON JacksonDataFormat (camel-jackson and camel-jackson3) 
> writes such a body as-is:
> * a file (WrappedFile), InputStream / StreamCache, byte[]: written as they are
> * a String whose trimmed text starts with { and ends with }, or [ and ], 
> written as it is; any other String is unchanged (encoded as a JSON string, 
> "hello")
> * POJO, Map, List and everything else: unchanged
> No parsing: the check is the type, and for a String the first and last 
> character. The Content-Type header is set as for any marshal. Not in the 
> shared AbstractJacksonDataFormat, which the binary Avro format extends too. 
> Upgrade guide note for 4.23: a String with JSON text is no longer 
> double-encoded.
> Found in the local-model benchmark (round 4, contracts/openapi-server): 
> routes that built the answer as JSON text and added marshal: json sent a 
> double-encoded answer in 3 of 10 steps; a WARN-only variant tested at night 
> took that to 0, this does it without the extra step.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to