jackson - 防止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}
对于我的一些代码,我需要双引号。我试图做一些配置我的休息路线但没有运气。任何人有一个修复的想法?
解决方案
你在评论中提到你有
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")
...
推荐阅读
- android-studio - Android Studio:将图像发送到 Whatsapp
- html - Firestore 在 Google App Script Web App 上获取所有文档并显示为 HTML 表格
- go - 如何使用 AWS SDK v2 在 dynamodb 中按键获取项目?
- javascript - 为什么这被绑定在这些箭头调用之一中,而不是另一个?
- node.js - 让一个后端管理 web 应用程序的身份验证并响应本机应用程序
- node.js - 每次用户请求受保护的路由时都可以在数据库中搜索吗?
- next.js - Next.js PWA 错误:清单:行:1,列:1,语法错误
- r - R:传递多个参数来累积/减少
- python - 我遇到了来自 concurrent.futures 的 ProcessPoolExecutor 的问题
- amazon-web-services - Amazon Rekognition 自定义标签