[英]Objectmapper.readValue does not deserialize correctly
I have a class:我有一个 class:
class MyClass extends HashMap <K, V> {
@JsonProperty ("filed 1")
public String field1;
@JsonProperty ("field 2")
public String field2;}
when using:使用时:
ObjectMapper.readValue ("jsonString", MyClass.class)
all values are written to the map, but I need nothing to be written to the map, the json string stores only values for field1 and field2.所有值都写入 map,但我不需要写入 map,json 字符串仅存储字段 1 和字段 2 的值。 What to do?
该怎么办?
Its very easy to do like this... you use a class like this...这样做很容易......你使用这样的 class ......
class MyClass {
@JsonProperty ("filed 1")
public String field1;
@JsonProperty ("field 2")
public String field2;
}
And then add a constructor to your HashMap
based class, which takes MyClass
as input and sets the values of the relevant fields correctly.然后将构造函数添加到基于
HashMap
的 HashMap 中,它将MyClass
作为输入并正确设置相关字段的值。
This way the code is equally good, but its easier to understand and maintain.这样代码同样好,但更容易理解和维护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.