骆驼路线:在Apache的骆驼自定义JSON输出xmljson
<camelContext xmlns="http://camel.apache.org/schema/spring">
<dataFormats>
<xmljson id="xmljson" />
</dataFormats>
<route id="route1">
<from uri="file:C:/Users/User1/InputXML"/>
<to uri="activemq:queue:MyThread1"/>
</route>
<route id="route2">
<from uri="activemq:queue:MyThread1"/>
<marshal ref="xmljson"/>
<bean ref="com.test.OutputProcessor"/>
</route>
</camelContext>
输入XML:
<?xml version="1.0" encoding="UTF-8"?>
<Message>
<to> Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</Message>
实际输出:
{"to":" Tove","from":"Jani","heading":"Reminder","body":"Don't forget me this weekend!"}
我想自定义此输出。我想添加一些mote属性到转换后的json。例如,我希望输出json为
{
"inputs":[
{
"inputname":"to",
"inputValue":"Tove"
},
{
"inputname":"from",
"inputValue":"jani"
},
{
"inputname":"heading",
"inputValue":"Reminder"
},
{
"inputname":"body",
"inputValue":"Don't forget me this weekend!"
}
]
}
这是如何实现的?
查看Apache Camel中的内容更丰富和消息转换器EIP。 – Namphibian
您是否基本问过如何将多个字符串转换为您显示的格式的单个JSON块(保存在变量中),每个块都由一组4对数据组成? 或者可能有超过4对的数据,例如'CC'值? – Mousey
可能有更多对。我真正想要的是在JSon中添加自定义属性,如“inputname”或“inputtype”,这些属性不是XML的一部分。 – KmrGtm