mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨 gson序列化时跳过File类型的字段
This commit is contained in:
parent
d6da675d31
commit
b08727b013
@ -1,21 +1,25 @@
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import me.chanjar.weixin.mp.bean.*;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCard;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardResult;
|
||||
import me.chanjar.weixin.mp.bean.card.membercard.WxMpMemberCardActivateTempInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.card.membercard.WxMpMemberCardUpdateResult;
|
||||
import me.chanjar.weixin.mp.bean.card.membercard.WxMpMemberCardUserInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
import me.chanjar.weixin.mp.bean.material.*;
|
||||
import me.chanjar.weixin.mp.bean.card.membercard.WxMpMemberCardActivateTempInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.card.membercard.WxMpMemberCardUpdateResult;
|
||||
import me.chanjar.weixin.mp.bean.card.membercard.WxMpMemberCardUserInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.result.*;
|
||||
import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -63,6 +67,22 @@ public class WxMpGsonBuilder {
|
||||
INSTANCE.registerTypeAdapter(WxMpMemberCardUserInfoResult.class, new WxMpMemberCardUserInfoResultGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMemberCardUpdateResult.class, new WxMpMemberCardUpdateResultGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMemberCardActivateTempInfoResult.class, new WxMpMemberCardActivateTempInfoResultGsonAdapter());
|
||||
|
||||
INSTANCE.setExclusionStrategies(new ExclusionStrategy() {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> aClass) {
|
||||
if (aClass == File.class) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Gson create() {
|
||||
|
Loading…
Reference in New Issue
Block a user