骆驼-轮询剩余端点和JSON拆分列表

问题描述 投票:0回答:1

所以我有一个rest API,它位于https://foo.bar/api,它返回一个空的json列表[]或包含1个或多个项目的列表:

[
    {
        "@class": "foo.bar.java.MyObject",
        "name": "Joe Bloggs"
    },
    {
        "@class": "foo.bar.java.MyObject",
        "name": "Fred Flinstone"
    }
]

现在,我正试图让骆驼从端点获取此数据,并将列表中的每个对象交给处理器。我尝试了以下方法:

fromF("timer://foo-poll?fixedRate=true&delay=5s&period=%d&bridgeErrorHandler=true", pollRate)
    .toF("https4://%s/%s", host, requestPath)
    .log("Received: ${body}")
    .split()
        .jsonpath("$")
        .log("Split: ${body}")
    .process(barProccessor);

以及各种尝试使用.unmarshal(new ListJacksonDataFormat(MyObject.class)).unmarshal().json(JsonLibrary.Jackson, List.class)解组数据的尝试没有任何效果的地方。

使用上面较大的代码块,没有错误,“ Split:$ {body}”日志消息打印机也没有输出。

无论上述API返回多少项目,使用上述两种方法解组都将引发此错误:

com.fasterxml.jackson.databind.exc.MismatchedInputException:否由于输入结束而要映射的内容

当那里

apache-camel unmarshalling polling
1个回答
0
投票

[好,如果有人遇到类似问题,我们设法弄清了这一点。工作路线生成器:

fromF("timer://foo-poll?fixedRate=true&delay=5s&period=%d&bridgeErrorHandler=true", pollRate)
    .toF("https4://%s/%s", host, requestPath)
    .log("Received: ${body}")
    .streamCaching("true")
    .unmarshal(new ListJacksonDataFormat(MyObject.class))
    .split()
        .jsonpath("$")
        .log("Split: ${body}")
    .process(barProccessor);

我已启用流缓存并使用杰克逊将列表解组。

© www.soinside.com 2019 - 2024. All rights reserved.