简体   繁体   English

JSON到XML转换中的错误:无法从START_ARRAY令牌中反序列化java.util.HashMap的实例

[英]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.

相关问题 无法将Java文件中的JSON文件转换为hashmap并出现错误,无法从START_ARRAY令牌中反序列化java.util.HashMap的实例 - convert JSON file to a hashmap in java with error Can not deserialize instance of java.util.HashMap out of START_ARRAY token 无法从 START_ARRAY 令牌反序列化 java.util.HashMap 的实例 - Can not deserialize instance of java.util.HashMap out of START_ARRAY token 忽略“无法从START_ARRAY令牌中反序列化java.util.LinkedHashMap的实例”错误 - Ignore the “Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token” error 使用Jackson反序列化JSON时出错:无法从START_ARRAY令牌中反序列化java.util.LinkedHashMap实例 - Error while deserializing JSON using Jackson : Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token 错误:无法在 [来源:N/A; 行:-1,列:-1] - Error: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token at [Source: N/A; line: -1, column: -1] 无法从我的“DataRequests”dto 中的 START_ARRAY 令牌中反序列化 java.util.LinkedHashMap 的实例 - Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token in my 'DataRequests' dto Java:Jackson String to Json-无法反序列化START_ARRAY令牌之外的实例 - Java: Jackson String to Json - Can not deserialize instance of out of START_ARRAY token Java Spring JSON分析错误:无法从START_ARRAY令牌中反序列化实例 - Java Spring JSON parse error: Cannot deserialize instance out of START_ARRAY token 无法使用START_ARRAY令牌反序列化对象实例 - Can not deserialize instance of object out of START_ARRAY token 无法反序列化实例,超出 START_ARRAY 令牌 - Can not deserialize instance, out of START_ARRAY token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM