我是否可以使用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>
这个通用解组器是否存在(希望确实存在),还是我应该实现自己的解组器?
谢谢!
答案 0 :(得分:0)
它不是完全的通用解组器,但与您要的类似:
创建REST服务时,可以设置BindingMode
,以便Camel会根据传入的Content-Type自动从JSON或XML解组:
restConfiguration()
.bindingMode(RestBindingMode.auto) // can also be .xml, .json,....
.component("servlet");
但是,我还没有看到此功能在REST服务之外使用或公开。
如果有兴趣,可以在RestBindingAdvice中执行。