方法一:
参考官方的方法实现的时候发现无效,添加如下代码即可。
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface FooAnnotation {
// some implementation here
}
参考:https://blog.csdn.net/lionliu6/article/details/50787893
方法二:
使用@Expose
首先要在new GsonBuilder()时,开启过滤功能
private GsonHelper() {
ExclusionStrategy excludeStrings