Jackson 动态更改 JsonIgnore [英] Jackson Change JsonIgnore Dynamically

查看:24
本文介绍了Jackson 动态更改 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.

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

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