首页 > 解决方案 > 防止camel-jackson去掉引号

问题描述

我正在为 REST 服务开发骆驼路线。我的任务是添加一个 POST,我需要在其中从发送的 json 中取出一个令牌。我正在执行以下操作:

.unmarshal().json(JsonLibrary.Jackson, Token.class)

我在我的 pom 文件中添加了“camel-jackson”依赖项,它工作正常。

问题:现在所有的json都去掉了双引号。所以下面的json:

{"name": "John Doe", "job": "farmer"}

结束为:

{name:John Doe,job:farmer}

对于我的一些代码,我需要双引号。我试图做一些配置我的休息路线但没有运气。任何人有一个修复的想法?

标签: jacksonapache-camelcamel-jackson

解决方案


你在评论中提到你有

restConfiguration()
    .component("jetty") 
    .scheme("https") 
    .bindingMode(RestBindingMode.auto) 
    .dataFormatProperty("prettyPrint", "true") 
    .port(8443);

你没有提到你的路线是什么。但是,如果您使用的是 bindingMode,它将期望 get()/post() 上的 type() 用于将 json 解组为。听起来您只想为要添加的新 POST 执行此操作,那么为什么不在 post() 上而不是在 restConfiguration() 上全局绑定呢?

例如

restConfiguration()
    .component("jetty") 
    .scheme("https") 
    .dataFormatProperty("prettyPrint", "true") 
    .port(8443);

rest("/words")
    .post("/new/post/url")
        .bindingMode(RestBindingMode.auto) 
        .type(YourPojo.class)
        ... 
    .get("existing/stuff")
        ... 

推荐阅读