杰克逊动态改变JsonIgnore [英] Jackson Change JsonIgnore Dynamically

查看:571
本文介绍了杰克逊动态改变JsonIgnore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,里面也有变量。有时我想忽略一些字段,有时候不反序列化(也许在序列化时)。我怎么能在杰克逊这样做?

I have a class and there are variables inside it as well. Sometimes I want to ignore some fields and sometimes not when deserializing (maybe at serializing too). How can I do it at Jackson?

推荐答案

对于序列化,过滤属性博客条目应该有所帮助。反序列化方面的支持较少,因为想要过滤掉写入的东西更为常见。

For serialization, "filtering properties" blog entry should help. Deserialization side has less support, since it is more common to want to filter out stuff that is written.

一种可能的方法是子类 JacksonAnnotationIntrospector ,覆盖方法(和/或字段)无法使用你想要的任何逻辑的方法。

One possible approach is to sub-class JacksonAnnotationIntrospector, override method(s) that introspect ignorability of methods (and/or fields) to use whatever logic you want.

它也可能如果你给出一个实际应用的例子,那就是帮助,即你试图阻止被反序列化的原因和原因。

It might also help if you gave an example of practical application, i.e what and why you are trying to prevent from being deserialized.

这篇关于杰克逊动态改变JsonIgnore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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