简体   繁体   English

使用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

I am trying to deserialize the json into MyClass object but every time I get the exception though I am able to serialize the JSON object. 我正在尝试将json反序列化为MyClass对象,但是每次我都能获得异常时,尽管我能够序列化JSON对象。

**com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token**

The json I am trying to deserialize is 我想反序列化的json是

 {
  "siteName": "avisports",
  "csAssetTypes": [
    "Content_C",
    [
      "name",
      "description",
      "subheadline",
      "abstract",
      "body",
      "headline",
      "subheadline",
      "avi_content_title",
      "avi_content_body",
      "avi_content_headline",
      "avi_content_abstract"
    ]
  ]
}

my Bean is something like 我的豆子有点像

public class GlContentServerConfig{

    private String siteName;
    private Map<String, List<String>> csAssetTypes = new HashMap<String, List<String>>();

    //getters ans setters
}

and my service method is 我的服务方法是

@Override
    public GlContentServerConfig getConfiguredAttributes(String siteName, String assetType) throws Exception {
        if (this.configMap == null) {
            this.configMap = this.configDAO.getAllConfigs();
        }

        GlContentServerConfig config = new GlContentServerConfig();
        config.setSiteName(siteName);               

        config.setCsAssetTypes(csService.getAssetTypeAttributeList(assetType));

        GloballinkConfig obj = this.configMap.get(siteName);
        if (obj != null) {
            String jsonValue = obj.getGlConfigValue();

            config=this.mapper.readValue(jsonValue, GlContentServerConfig.class); // error comes from this line
            //List<GlContentServerConfig> glconfigList= this.mapper.readValue(jsonValue, new TypeReference<GlContentServerConfig>(){});
            //List<GlContentServerConfig> glconfigList = this.mapper.readValue(jsonValue, this.mapper.getTypeFactory().constructCollectionType(List.class, GlContentServerConfig.class));

            System.out.println("final : "+glconfigList.toString());

        }

        return config;
    }

I have tried all most all of the permutations and combinations. 我已经尝试了所有大多数排列和组合。 Few of them are commented in the code. 代码中几乎没有注释它们。 I am unable to figure out the way to use Jackson. 我无法弄清楚使用Jackson的方式。 please help me out. 请帮帮我。

add @JsonProperty("csAssetTypes") to your Bean : @JsonProperty("csAssetTypes")添加到您的Bean中:

public class GlContentServerConfig{

    private String siteName;
@JsonProperty("csAssetTypes") 
    private Map<String, List<String>> csAssetTypes = new HashMap<String, List<String>>();

    //getters ans setters
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 忽略“无法从START_ARRAY令牌中反序列化java.util.LinkedHashMap的实例”错误 - Ignore the “Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token” error 无法从我的“DataRequests”dto 中的 START_ARRAY 令牌中反序列化 java.util.LinkedHashMap 的实例 - Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token in my 'DataRequests' dto 错误:无法在 [来源: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] 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 Java:Jackson String to Json-无法反序列化START_ARRAY令牌之外的实例 - Java: Jackson String to Json - Can not deserialize instance of out of START_ARRAY token 用杰克逊反序列化json对象的对象列表-无法从start_array令牌反序列化实例 - deserializing a list of objects json object with jackson - cannot deserialize instance out of start_array token 无法将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 Codehaus Jackson JSON数据转换为POJO无法反序列化实例...超出START_ARRAY令牌 - Codehaus Jackson JSON data to POJO Can not deserialize instance … out of START_ARRAY token 杰克逊数组或字符串:无法从START_ARRAY令牌中反序列化java.lang.String实例 - Jackson array or string: Can not deserialize instance of java.lang.String out of START_ARRAY token Jackson 错误:无法从 START_ARRAY 令牌反序列化 `java.lang.String` 的实例 - Jackson error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM