apache-camel - Camel unmarshaller 支持多种数据格式
问题描述
是否有一个 Camel 解组器,我可以使用它来将多种数据格式(JSON、XML 等)解组为 XML?
然后,这个“通用”解组器将用作例如:
<route id="myRoute">
<from uri="file:test/input"/>
<!-- The input can be in JSON or in XML -->
<unmarshal ref="universalUnmarshallerToXML"/>
<!-- The input payload is always in XML -->
<choice >
<when>
<xpath>/order/customer/country = 'US'</xpath>
<to uri="file:test/output/us"/>
</when>
<when>
<xpath>/order/customer/country = 'UK'</xpath>
<to uri="file:test/output/uk"/>
</when>
<otherwise>
<to uri="file:test/output/others"/>
</otherwise>
</choice>
</route>
这个通用解组器是否存在(希望它确实存在),还是我应该实现自己的?
谢谢!
解决方案
它不完全是一个通用的 unmarshaller,但类似于您所要求的:
当你创建一个 REST 服务时,你可以设置一个BindingMode
以便 Camel 会根据传入的 Content-Type 自动从 JSON 或 XML 解组:
restConfiguration()
.bindingMode(RestBindingMode.auto) // can also be .xml, .json,....
.component("servlet");
但是,我还没有看到这个功能被使用或暴露在 REST 服务之外。
如果您有兴趣,实现在RestBindingAdvice中。
推荐阅读
- r - 如何选择具有一定连续数的数据
- c# - 来自不同类的 Lambda 表达式中的多个 Where 子句
- python - 随机数,小数
- php - 我应该在 nginx.conf 或 Laravel config/cors.php 中添加我的 CORS 标头吗?
- svg - 对多维交叉滤波器求和以减少维数
- swift5 - 如何找到进度(Progress)对象的子级?
- amazon-web-services - 无法在 EC2 上创建 AudioDevices・Spring-Boot
- python - 交互失败 discord.py 按钮
- c# - 如何在变量字符串c#中插入双引号
- spring - 将 application.yml 文件(在我的应用程序中可用)读入 spring boot 中添加的依赖模块