我有一个json响应,我使用Apache Valocity模板将其转换为xml。我的JSON的格式如下:使用Apache Velocity模板的Json映射
{
"value": {
"1234": {
"7": ["abcde"],
"2": ["abcde", "lkisy", "skjsk"],
"1": ["aksdja", "msnd", "knsda"]
},
"7654": {
"8": ["NA"],
"4": ["NA"],
"7": ["BA"]
},
"0987": {
"8": ["PO"],
"3": ["LO"],
"2": ["KI"]
}
}
}
我Velocity模板的格式如下:
<VelocityResponse xmlns="xsd location namespace">
<HeaderID>${headers.HeaderID}</HeaderID>
<FirstTag>
#foreach($body in ${body.value})
<SecondTag>
#set($keys = $body.keySet())
#foreach($key in $keys)
<ThirdTag>$key</ThirdTag>
#set($someValue = $key.keySet())
#foreach($value in $someValue)
<FourthTag>$value</FourthTag>
<FifthTag>
#foreach($userInfo in $someValue[$value])
<SixthTag>$userInfo</SixthTag>
#end
</FifthTag>
#end
</SecondTag>
#end
</FirstTag>
</VelocityResponse>
当我尝试映射此,我收到此错误:
198 - org.apache.camel.camel-core - 2.15.1.redhat-621084 | Error : org.apache.velocity.exception.ParseErrorException: Encountered "<EOF>" at org.apache.camel.component.velocity.VelocityEndpoint[line 21, column 27]
n | Was expecting one of:
n | "(" ...
n | <RPAREN> ...
n | <ESCAPE_DIRECTIVE> ...
n | <SET_DIRECTIVE> ...
n | "##" ...
n | "\\\\" ...
n | "\\" ...
n | <TEXT> ...
n | "*#" ...
n | "*#" ...
n | "]]#" ...
n | <STRING_LITERAL> ...
n | <END> ...
n | <IF_DIRECTIVE> ...
n | <INTEGER_LITERAL> ...
n | <FLOATING_POINT_LITERAL> ...
n | <WORD> ...
n | <BRACKETED_WORD> ...
n | <IDENTIFIER> ...
n | <DOT> ...
n | "{" ...
n | "}" ...
n | <EMPTY_INDEX> ...
n |
得到任何想法?
请检查速度模板中使用的所有变量是否也在速度模型中。不确定,在第一个foreach中,“$ {body.value}”是正确的。如果body在你的模型中,也尝试使用getter在模板中访问它,如$ body.getValue() – dumitru
嗨,实际上我正在获取值。 –