我正在将Mule从3.9迁移到4.1.4,尝试将ArrayList转换为JSON,然后将其发布到JMS队列(使用ActiveMQ),得到以下错误消息
代码:
<sub-flow name="xxxx_part_data_to_messaging_system_flow">
<logger level="INFO" doc:name="Logger" doc:id="0607190d-f3ed-4b1b-a5b4-3572c08cf2d5" message='[vars.correlationId ++ "" ++ vars.batch_id]'/>
<jms:publish doc:name="xxxx-part-data-jms-queue" doc:id="b44b1880-7374-4e4d-a0e0-1b4ab193ade4" config-ref="transactional_data_jms_connection_config" destination="${ld.transaction.xxxx.part.messaging.queue}">
<jms:message >
<jms:body ><![CDATA[#[[payload]]]]></jms:body>
</jms:message>
</jms:publish>
<logger message="#[" $(vars.correlationId)-$(vars.batch_id) xxxx part posted successfully into transaction data queue ${ld.transaction.xxxx.part.messaging.queue}"]" level="INFO" doc:name="Logger" />
</sub-flow>
错误:
the data fetched from DB is ArrayList
An error occurred while sending a message to the QUEUE: [ld.stock.part.queue]:
Invalid type passed to StreamMessage: java.util.ArrayList . Allowed types are:
Boolean, Byte, Short, Character, Integer, Long, Float, Double,String and
byte[]. Invalid type passed to StreamMessage: java.util.ArrayList . Allowed
types are: Boolean, Byte, Short, Character, Integer, Long, Float, Double,String
and byte[].
Error type : JMS:ILLEGAL_BODY
答案 0 :(得分:2)
您的有效负载不是JSON。您正在使用额外的[]:#[[payload]]
将有效载荷包装在一个数组中,该默认值将为application / java。
您可以转换为JSON内联。如果要使用周围的阵列,请使用:
#[output application/json --- [payload]]
或者,如果您不需要额外使用数组:
#[output application/json --- payload]
内联示例:
<jms:publish doc:name="xxxx-part-data-jms-queue" doc:id="b44b1880-7374-4e4d-a0e0-1b4ab193ade4" config-ref="transactional_data_jms_connection_config" destination="${ld.transaction.xxxx.part.messaging.queue}">
<jms:message >
<jms:body ><![CDATA[#[[output application/json --- payload]]]]></jms:body>
</jms:message>
</jms:publish>