Apache 骆驼休息 dsl RestBindingMode.json 不起作用

vas*_*hth 2 apache-camel spring-camel

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

SpringRouteBuilder

@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");

    }

}
Run Code Online (Sandbox Code Playgroud)

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

Pom 依赖

    <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>
Run Code Online (Sandbox Code Playgroud)

例外

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]
Run Code Online (Sandbox Code Playgroud)

bur*_*rki 12

Check if you have the dependency camel-jackson included in your project.