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