在使用Jackson反序列化期间选择性地忽略JSON属性 [英] Selectively ignoring JSON properties during deserialize with Jackson

查看:326
本文介绍了在使用Jackson反序列化期间选择性地忽略JSON属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在反序列化阶段有选择地忽略JSON属性。我目前正在处理一个巨大的JSON文件,需要很长时间才能在慢速Android设备上反序列化,我想在应用程序生命周期的不同阶段指定一些不反序列化的属性。问题是,有时我需要数据,我需要能够在实际需要时反序列化被忽略的数据。

I want to selectively ignore JSON properties during the deserialization phase. 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. The problem is, sometimes I need the data and I need to be able to deserialize the ignored data when I actually need it.

我正在使用Jackson和ObjectMapper。

I'm using Jackson and ObjectMapper.

示例POJO:

public class Pojo {
    private String name;
    private Map<String, String> data;

    ...
}

示例JSON:

{
    "pojos" : [ {
        name : "Name",
        data : {
            "somedata1" : "somevalue1",
            "somedata2" : "somevalue2",
            "somedata3" : "somevalue3"
            ...
        }
    } ]
}

会有大量的pojos和每个数据 财产将变得巨大。所以我想有时反序列化忽略数据属性。有时我希望数据正常反序列化。

There will be great amount of "pojos" and each "data" property will get HUGE. So I would like to sometimes deserialize with ignoring the "data" property. Sometimes I want the "data" to deserialize normally.

推荐答案

通过使用不同的类,您可以创建一个适合该类的超类在服务接口中,然后创建2个或更多子类...所以希望在服务中不应该更改任何内容

by using different classes you can create a superclass that fits with the class in the service interface and then create 2 or more subclasses...so hopefully nothing should be changed in the service

这篇关于在使用Jackson反序列化期间选择性地忽略JSON属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆