Claus Ibsen created CAMEL-25998:
-----------------------------------
Summary: camel-groovy - groovyJson cannot marshal a List, also the
List its unmarshal gives for a JSON array
Key: CAMEL-25998
URL: https://issues.apache.org/jira/browse/CAMEL-25998
Project: Camel
Issue Type: Bug
Components: camel-groovy
Affects Versions: 4.18.0, 4.22.0, 4.23.0
Reporter: Claus Ibsen
Fix For: 4.24.0
The groovyJson data format writes a Map, a Groovy {{Node}} or a Jackson
{{JsonNode}} as JSON. Any other body goes through
{{mandatoryConvertTo(byte[])}} and is written as it is
({{GroovyJSonlDataFormat}}, main 50d17f9c2614, line 61). There is no type
converter from a {{List}} to a {{byte[]}}, so marshal of a List fails:
{{TypeConversionException: Error during type conversion from type:
java.lang.String to the required type: byte[] due to
java.lang.IllegalArgumentException: argument type mismatch}}. This includes the
List that unmarshal of a JSON array gives. The data format docs list "Java List
object" as a body that marshal takes.
groovyXml has the same path ({{GroovyXmlDataFormat}}, line 107) and fails the
same way for a List. There, a List has no root element, so a clear error is
enough.
Checked on 4.24.0-SNAPSHOT with {{camel run}}:
* {{[\{"id":1\},\{"id":2\}]}}, then {{unmarshal: groovyJson}}: an {{ArrayList}}
of {{LazyMap}}, as expected;
* then {{marshal: groovyJson}}: the {{TypeConversionException}} above;
* a List of two Maps with {{marshal: groovyXml}}: the same.
*Proposed change*: write a List (or another Collection) as a JSON array in
groovyJson, as JsonOutput does. In groovyXml, fail with an
{{InvalidPayloadException}} that says a List has no root element.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)