Claus Ibsen created CAMEL-25285:
-----------------------------------
Summary: marshal/unmarshal on a null message body: say the body is
null
Key: CAMEL-25285
URL: https://issues.apache.org/jira/browse/CAMEL-25285
Project: Camel
Issue Type: Improvement
Components: camel-core
Reporter: Claus Ibsen
*unmarshal* with a null message body fails, for any data format (checked with
json/Jackson and csv on 4.23.0-SNAPSHOT), with:
{noformat}NoTypeConversionAvailableException: No type converter available to
convert from type: null to the required type: java.io.InputStream{noformat}
The message names neither the data format nor the actual cause, which is that
the body is null. UnmarshalProcessor already has {{allowNullBody}} to skip a
null body, but the error does not mention it. Proposal: fail with a clear
message, for example:
{noformat}Cannot unmarshal using json-jackson: the message body is null, so
there is nothing to unmarshal. Set the body first, or set allowNullBody=true to
skip a null body.{noformat}
*marshal* with a null body never fails, and the result depends on the format:
* json (Jackson): the 4-character string {{null}}
* csv: an empty string
* jacksonXml: {{<null/>}}
A REST route that marshals a lookup result which came back null answers 200
with the body {{null}}. Since null is valid JSON this should not become an
error by default; CAMEL-25284 adds {{allowNullBody}} to marshal.
Repro (YAML DSL):
{code:yaml}
- route:
from:
uri: timer:t
parameters: {repeatCount: 1}
steps:
- setBody: {simple: "${null}"}
- unmarshal:
json:
library: Jackson
{code}
Found while benchmarking a local model editing a route through camel-jbang-mcp:
the model replaced the step that loads a file into the body with unmarshal, got
the type converter message, did not recognize the cause, and reported the
change as done.
Related: CAMEL-24844 (the validator follows the body type from step to step and
could flag an unmarshal with nothing to unmarshal before the route runs).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)