首页 技术 正文
技术 2022年11月9日
0 收藏 701 点赞 4,899 浏览 2659 个字

@JsonIgnore不仅仅是在getter上有影响,也对setter方法有影响:

所在包:com.fasterxml.jackson.annotation;

源码:

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;/**
* Marker annotation that indicates that the annotated method or field is to be//标记方法或字段
* ignored by introspection-based//被标记的方法和字段不进行序列化和反序列化
* serialization and deserialization functionality. That is, it should
* not be consider a "getter", "setter" or "creator".//实际上就是:这个注解不能被认为是一个getter,setter或creator
*<p>
* In addition, starting with Jackson 1.9, if this is the only annotation//1.9版本如果仅加入此注解,将会导致整个属性被忽视
* associated with a property, it will also cause the whole
* property to be ignored: that is, if setter has this annotation and//如果在setter上注解,在getter上不注解,那么getter也会受影响(将不会被序列化)
* getter has no annotations, getter is also effectively ignored.
* It is still possible for different accessors to use different//不同的存取器可以用不同的注解
* annotations; so if only "getter" is to be ignored, other accessors//如果仅是getter加了此注解,那么其他的存取器(setter或字段)
* (setter or field) would need explicit annotation to prevent//需要明确地被注解以防止不被序列化(通常使用@JsonProperty来注解)
* ignoral (usually {@link JsonProperty}).
* <p>
* For example, a "getter" method that would otherwise denote
* a property (like, say, "getValue" to suggest property "value")
* to serialize, would be ignored and no such property would
* be output unless another annotation defines alternative method to use.
*<p>
* Before version 1.9, this annotation worked purely on method-by-method (or field-by-field)
* basis; annotation on one method or field did not imply ignoring other methods
* or fields. However, with version 1.9 and above, annotations associated
* with various accessors (getter, setter, field, constructor parameter) of
* a logical property are combined; meaning that annotations in one (say, setter)
* can have effects on all of them (if getter or field has nothing indicating
* otherwise).
*<p>
* Annotation is usually used just a like a marker annotation, that
* is, without explicitly defining 'value' argument (which defaults
* to <code>true</code>): but argument can be explicitly defined.
* This can be done to override an existing JsonIgnore by explicitly
* defining one with 'false' argument.
*<p>
* Annotation is similar to {@link javax.xml.bind.annotation.XmlTransient}
*/
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
public @interface JsonIgnore
{
/**
* Optional argument that defines whether this annotation is active
* or not. The only use for value 'false' if for overriding purposes
* (which is not needed often); most likely it is needed for use
* with "mix-in annotations" (aka "annotation overrides").
* For most cases, however, default value of "true" is just fine
* and should be omitted.
*/
boolean value() default true;
}

JsonIgnore可以标注在字段、方法上(1.9版本及以上),当注解@JsonIgnore时,会发生两件事:

①:不会被jackson解析;

②:所修饰的字段或方法不参与序列化过程

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290