[英]error in JSON to XML conversion: Can not deserialize instance of java.util.HashMap out of START_ARRAY token
I'm completely new to this thing, I'm trying to convert JSON to XML in groovyscript, here's the code: 我对这件事是完全陌生的,我正在尝试将groovyscript中的JSON转换为XML,这是代码:
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlUtil
def xmlBuilder = new StreamingMarkupBuilder()
def item = payload
writer = xmlBuilder.bind {
mkp.declareNamespace( ns1: "TV")
'ns1:tranfer ' {
'merchant_id'()
'surveyYear'()
'merchant_password' ()
'email'(item.AdditionalInfo.ClientEmail)
'amount'(item.Amount)
'reference_code'(item.WithdrawalId)
}
}
return XmlUtil.serialize( writer )
I'm using anypoint studio and SOAP UI for testing. 我正在使用Anypoint Studio和SOAP UI进行测试。
When I use a single JSON element like this, it works 当我使用单个JSON元素时,它可以工作
{
"WithdrawalId": 12345,
"LegalEntity" : "xkvt",
"ProviderReference": "123xyz",
"Currency": "USD",
"Amount": 77,
"AdditionalInfo": {"ClientEmail":"test@test.com","CustomFieldX":"x"}
}
But when I add another element to JSON, it is unable to "deserialize" 但是,当我向JSON添加另一个元素时,它无法“反序列化”
[
{
"WithdrawalId": 12345,
"LegalEntity" : "xkvt",
"ProviderReference": "123xyz",
"Currency": "USD",
"Amount": 757,
"AdditionalInfo": {"ClientEmail" : "tony@gmail.com"} },
{
"WithdrawalId": 12345,
"LegalEntity" : "xkvt2",
"ProviderReference": "123xyz",
"Currency": "USD",
"Amount": 7808,
"AdditionalInfo": {"ClientEmail" : "tony@gmail.com"} }
]
Here's the exact error thrown on SOAPui: 这是在SOAPui上引发的确切错误:
"<data contentType="null" contentLength="113"><![CDATA[Failed to transform from "json" to "java.util.HashMap". (org.mule.api.transformer.TransformerMessagingException).]]></data>"
Any ideas how I can solve this? 有什么想法可以解决这个问题吗? Thanks!
谢谢!
How is your mapper configured. 映射器的配置方式。 Try including the line below in your mapper configuraiton - mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
尝试在映射器配置中包括以下行-mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.