如何聚合数据(java.util.Map)格式以构造JSON有效负载。 例如 -
"listings": [
{
"listingId":"7676762734623",
"section": "section-100",
"products":
[
{"row":"A4","seat":"11"}
]
},
... 100 more such listings arrays
答案 0 :(得分:0)
您可以在脚本中使用groovy:component并使用json转换器或使用Custom Transformer。见这个例子:
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("fill","none");
map1.put("stroke","#fff");
Map<String, Object> map = new HashMap<String, Object>();
map.put("content", map1);
return map;]]></scripting:script>
</scripting:component>
<json:object-to-json-transformer doc:name="Object to JSON"/>
答案 1 :(得分:-1)
您可以编写一个Java组件,将数据聚合到Map并将其转换为JSON消息。请仔细阅读SO link