简体   繁体   English

杰克逊反序列化课程

[英]Jackson deserialization of class

Is it possible to deserialize the example below using Jackson? 是否可以使用杰克逊反序列化下面的示例?

public class A extends HashMap<String,String> {
   //No other methods here for now
}

.... ....

JSON Looks like this: JSON看起来像这样:

{"something": 
   {
   "entry":
   [
     {"key":"one", "value":"avalue"}, 
     {"key":"two", "value":"bvalue"}
   ]
  }
}

... ...

At this time I'm getting error saying: Unrecognized Property Exception for entry. 这时,我收到错误消息:输入的无法识别的属性异常。

Any help would be greatly appreciated. 任何帮助将不胜感激。

First, your json is wrong, but I think I see what you're trying. 首先,您的json是错误的,但我想我知道您在尝试什么。

No it's not possible. 不,这不可能。 HashMap<String,String> implies your object contains only top level string properties like: HashMap<String,String>表示您的对象仅包含顶级字符串属性,例如:

{
    "something": "value",
    "somethingelse": "value2",
    "someAdditionalThing": "value3"
}

To deserialize that you probably need to have a more strongly typed object. 要反序列化,可能需要一个更强类型的对象。 Jackson is falling over trying to turn: 杰克逊(Jackson)因试图转向而跌倒

{
    "entry":
        [
            {"key":"one", "value":"avalue"}, 
            {"key":"two", "value":"bvalue"}
        ]
}

Into a string. 变成一个字符串。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM