All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wujiuye.hotkit.json.gson.GsonExclusionStrategy Maven / Gradle / Ivy

Go to download

hotkits项目集合中的一员,JSON适配器组件,让切换JSON解析框架只需要切换依赖包即可。

The newest version!
package com.wujiuye.hotkit.json.gson;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

import java.lang.reflect.Modifier;

/**
 * 自定义的gson序列化策略
 *
 * @author wujiuye 2020/04/26
 */
public class GsonExclusionStrategy implements ExclusionStrategy {

    @Override
    public boolean shouldSkipField(FieldAttributes fieldAttributes) {
        // 如果字段被transient关键字修饰,则不参与序列化(Gson默认已经支持)
        return fieldAttributes.hasModifier(Modifier.TRANSIENT);
    }

    @Override
    public boolean shouldSkipClass(Class aClass) {
        return false;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy