首页 > 解决方案 > Camel rest JSON 使用 START_ARRAY 反序列化

问题描述

我正在尝试将application/json休息服务转换为 POJO 列表。但我不能

我的输入是我无法引用列表的列表Eventcamel:put

<dataFormats>
  <json id="eventJsonList" prettyPrint="true" library="Jackson" useList="true"
    unmarshalTypeName="example.model.Event" />
</dataFormats>

<camel:rest path="events" consumes="application/json" produces="application/json">
  <camel:put 
    uri="/save">
    <to uri="direct:save-events" />
  </camel:put>
</camel:rest>

使用Camel 2.22

标签: apache-camel

解决方案


我认为您需要使用camel:unmarshall来告诉路线使用您的数据格式。

<camel:rest path="events" consumes="application/json" produces="application/json">
    <camel:put uri="/save">
        <camel:route>
            <camel:unmarshal ref="eventJsonList" />
            <camel:to uri="direct:save-events" />
        </camel:route>
    </camel:put>
</camel:rest>

推荐阅读