[英]Selectively ignoring JSON properties during deserialize with Jackson
I want to selectively ignore JSON properties during the deserialization phase. 我想在反序列化阶段选择性地忽略JSON属性。 I'm currently dealing with a huge JSON file that takes ages to deserialize on slow Android devices and I would like to specify some properties not to be deserialized at different stages of the app lifecycle.
我目前正在处理一个巨大的JSON文件,该文件需要花费很多时间才能在慢速的Android设备上反序列化,并且我想指定一些属性,这些属性在应用程序生命周期的不同阶段不进行反序列化。 The problem is, sometimes I need the data and I need to be able to deserialize the ignored data when I actually need it.
问题是,有时我需要数据,而当我实际需要它时,我需要能够反序列化被忽略的数据。
I'm using Jackson and ObjectMapper. 我正在使用Jackson和ObjectMapper。
Example POJO: 示例POJO:
public class Pojo {
private String name;
private Map<String, String> data;
...
}
Example JSON: JSON示例:
{
"pojos" : [ {
name : "Name",
data : {
"somedata1" : "somevalue1",
"somedata2" : "somevalue2",
"somedata3" : "somevalue3"
...
}
} ]
}
There will be great amount of "pojos" and each "data" property will get HUGE. 将会有大量的“ pojos”,并且每个“ data”属性都将变得巨大。 So I would like to sometimes deserialize with ignoring the "data" property.
因此,我有时会反序列化而忽略“ data”属性。 Sometimes I want the "data" to deserialize normally.
有时我希望“数据”正常反序列化。
通过使用不同的类,您可以在服务接口中创建适合该类的超类,然后创建2个或更多子类...因此希望服务中无需进行任何更改
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.