首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Apache camel rest dsl RestBindingMode.json不工作

Apache camel rest dsl RestBindingMode.json不工作
EN

Stack Overflow用户
提问于 2018-10-23 13:53:08
回答 1查看 3.4K关注 0票数 3

我正在尝试使用camel dsl构建rest。我试过多个提供者,火花休息,码头。但是当我使用RestBindingMode.json时,它会抛出封送异常,如果我删除rest绑定模式,它可以正常工作。

SpringRouteBuilder

代码语言:javascript
运行
复制
@Component
public class RestAPIRoutes extends SpringRouteBuilder {

    @Override
    public void configure() throws Exception {
        restConfiguration().component("spark-rest")
            .bindingMode(RestBindingMode.json)
            .port(8787)
            .dataFormatProperty("prettyPrint","true");

        rest("/balance").produces("application/json").consumes("application/json")
            /* mock api */
            .get("/query").route().bean(BalanceService.class,"fetchBalance").endRest()
            /* fetch balance by msisdn*/
            .get("/query/{msisdn}").description("Fetch line balance by msisdn")
                .type(BalanceInfo.class).to("bean:balanceService?method=fetchBalance(${header.msisdn})")
            .post("/update").type(BalanceInfo.class).outType(BalanceInfo.class).to("bean:balanceService?method=updateBalance");

    }

}

这里,balanceService是一个带有重载方法的简单Spring @Service,而BalanceInfo是带有两个字段和getter设置器的简单pojo类。

Pom依赖性

代码语言:javascript
运行
复制
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spark-rest</artifactId>
        <version>2.22.1</version>
    </dependency>
<dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>2.22.1</version>
        </dependency>

异常

代码语言:javascript
运行
复制
org.apache.camel.processor.binding.BindingException: Cannot bind to json as message body is not json compatible. Exchange[ID-LTB0202777-MAC-1540301942376-3-1]
    at org.apache.camel.processor.RestBindingAdvice.unmarshal(RestBindingAdvice.java:317) ~[camel-core-2.22.1.jar:2.22.1]
    at org.apache.camel.processor.RestBindingAdvice.before(RestBindingAdvice.java:137) ~[camel-core-2.22.1.jar:2.22.1]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-23 14:46:35

检查项目中是否包含了依赖项camel-jackson

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52950835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档