Java Code Examples for com.google.gson.ExclusionStrategy

The following are top voted examples for showing how to use com.google.gson.ExclusionStrategy. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: DaUtil   File: WJsonUtils.java   Source Code and License 7 votes vote down vote up
/**
 * 构建通用GsonBuilder, 封装初始化工作
 *
 * @return
 */
public static GsonBuilder getGsonBuilder(boolean prettyPrinting) {
	GsonBuilder gb = new GsonBuilder();
	gb.setDateFormat("yyyy-MM-dd HH:mm:ss:mss");
	gb.setExclusionStrategies(new ExclusionStrategy() {
		@Override
		public boolean shouldSkipField(FieldAttributes f) {
			return f.getAnnotation(WJsonExclued.class) != null;
		}

		@Override
		public boolean shouldSkipClass(Class<?> clazz) {
			return clazz.getAnnotation(WJsonExclued.class) != null;
		}
	});
	if (prettyPrinting)
		gb.setPrettyPrinting();
	return gb;
}
 
Example 2
Project: Camel   File: GsonMarshalExclusionTest.java   Source Code and License 7 votes vote down vote up
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {

            GsonDataFormat weightExclusionFormat = new GsonDataFormat(TestPojoExclusion.class);
            weightExclusionFormat.setExclusionStrategies(Arrays.<ExclusionStrategy>asList(new WeightExclusionStrategy()));
            from("direct:inPojoExcludeWeight").marshal(weightExclusionFormat);
            from("direct:backPojoExcludeWeight").unmarshal(weightExclusionFormat).to("mock:reversePojoExcludeWeight");

            //START SNIPPET: format
            GsonDataFormat ageExclusionFormat = new GsonDataFormat(TestPojoExclusion.class);
            ageExclusionFormat.setExclusionStrategies(Arrays.<ExclusionStrategy>asList(new AgeExclusionStrategy()));
            from("direct:inPojoExcludeAge").marshal(ageExclusionFormat);
            //END SNIPPET: format
            from("direct:backPojoExcludeAge").unmarshal(ageExclusionFormat).to("mock:reversePojoExcludeAge");
        }
    };
}
 
Example 3
Project: ti.box   File: Excluder.java   Source Code and License 7 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 4
Project: lancoder   File: WebApi.java   Source Code and License 7 votes vote down vote up
public WebApi(Master master, WebApiListener eventListener) {
	this.master = master;
	this.eventListener = eventListener;
	WebApi.gson = new GsonBuilder().registerTypeAdapter(CodecEnum.class, new CodecTypeAdapter<>())
			.setExclusionStrategies(new ExclusionStrategy() {
				@Override
				public boolean shouldSkipField(FieldAttributes f) {
					return f.getAnnotation(NoWebUI.class) != null;
				}

				@Override
				public boolean shouldSkipClass(Class<?> clazz) {
					return false;
				}
			}).serializeSpecialFloatingPointValues().create();
}
 
Example 5
Project: letv   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
    if (this.version != IGNORE_VERSIONS && !isValidVersion((Since) clazz.getAnnotation(Since.class), (Until) clazz.getAnnotation(Until.class))) {
        return true;
    }
    if (!this.serializeInnerClasses && isInnerClass(clazz)) {
        return true;
    }
    if (isAnonymousOrLocal(clazz)) {
        return true;
    }
    for (ExclusionStrategy exclusionStrategy : serialize ? this.serializationStrategies : this.deserializationStrategies) {
        if (exclusionStrategy.shouldSkipClass(clazz)) {
            return true;
        }
    }
    return false;
}
 
Example 6
Project: odoo-work   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 7
Project: lams   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 8
Project: DAFramework   File: WJsonUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 构建通用GsonBuilder, 封装初始化工作
 *
 * @return
 */
public static GsonBuilder getGsonBuilder(boolean prettyPrinting) {
	GsonBuilder gb = new GsonBuilder();
	gb.setDateFormat("yyyy-MM-dd HH:mm:ss:mss");
	gb.setExclusionStrategies(new ExclusionStrategy() {
		@Override
		public boolean shouldSkipField(FieldAttributes f) {
			return f.getAnnotation(WJsonExclued.class) != null;
		}

		@Override
		public boolean shouldSkipClass(Class<?> clazz) {
			return clazz.getAnnotation(WJsonExclued.class) != null;
		}
	});
	if (prettyPrinting)
		gb.setPrettyPrinting();
	return gb;
}
 
Example 9
Project: mvvm-template   File: GsonProvider.java   Source Code and License 6 votes vote down vote up
/**
 * Make gson which {@link DateDeserializer} and compatible with {@link RealmObject}
 * @return {@link Gson} object
 */
public static Gson makeGsonForRealm() {
    return makeDefaultGsonBuilder()
            .setExclusionStrategies(new ExclusionStrategy() {
                @Override
                public boolean shouldSkipField(FieldAttributes f) {
                    return f.getDeclaringClass().equals(RealmObject.class);
                }

                @Override
                public boolean shouldSkipClass(Class<?> clazz) {
                    return false;
                }
            })
            .create();
}
 
Example 10
Project: boohee_v5.6   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
    if (this.version != IGNORE_VERSIONS && !isValidVersion((Since) clazz.getAnnotation(Since
            .class), (Until) clazz.getAnnotation(Until.class))) {
        return true;
    }
    if (!this.serializeInnerClasses && isInnerClass(clazz)) {
        return true;
    }
    if (isAnonymousOrLocal(clazz)) {
        return true;
    }
    for (ExclusionStrategy exclusionStrategy : serialize ? this.serializationStrategies :
            this.deserializationStrategies) {
        if (exclusionStrategy.shouldSkipClass(clazz)) {
            return true;
        }
    }
    return false;
}
 
Example 11
Project: wES   File: WJsonUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 构建通用GsonBuilder, 封装初始化工作
 *
 * @return
 */
public static GsonBuilder getGsonBuilder(boolean prettyPrinting) {
	GsonBuilder gb = new GsonBuilder();
	gb.setDateFormat("yyyy-MM-dd HH:mm:ss:mss");
	gb.setExclusionStrategies(new ExclusionStrategy() {
		@Override
		public boolean shouldSkipField(FieldAttributes f) {
			return f.getAnnotation(WJsonExclued.class) != null;
		}

		@Override
		public boolean shouldSkipClass(Class<?> clazz) {
			return clazz.getAnnotation(WJsonExclued.class) != null;
		}
	});
	if (prettyPrinting)
		gb.setPrettyPrinting();
	return gb;
}
 
Example 12
Project: wES   File: WGsonConvert.java   Source Code and License 6 votes vote down vote up
/**
 * 构建通用GsonBuilder, 封装初始化工作
 *
 * @return
 */
public static GsonBuilder getGsonBuilder(boolean prettyPrinting) {
	GsonBuilder gb = new GsonBuilder();
	gb.setDateFormat("yyyy-MM-dd HH:mm:ss:mss");
	gb.setExclusionStrategies(new ExclusionStrategy() {
		@Override
		public boolean shouldSkipField(FieldAttributes f) {
			return f.getAnnotation(WJsonExclued.class) != null;
		}

		@Override
		public boolean shouldSkipClass(Class<?> clazz) {
			return clazz.getAnnotation(WJsonExclued.class) != null;
		}
	});
	if (prettyPrinting)
		gb.setPrettyPrinting();
	return gb;
}
 
Example 13
Project: mycore   File: MCRPIRegistrationService.java   Source Code and License 6 votes vote down vote up
public static void addFlagToObject(MCRBase obj, MCRPI databaseEntry) {
    String json = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
        @Override
        public boolean shouldSkipField(FieldAttributes fieldAttributes) {
            String name = fieldAttributes.getName();

            return Stream.of("mcrRevision", "mycoreID", "id", "mcrVersion")
                .anyMatch(field -> field.equals(name));
        }

        @Override
        public boolean shouldSkipClass(Class<?> aClass) {
            return false;
        }
    }).create().toJson(databaseEntry);
    obj.getService().addFlag(PI_FLAG, json);
}
 
Example 14
Project: odoo-follow-up   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 15
Project: Forage   File: OkApiModule.java   Source Code and License 6 votes vote down vote up
/**
 * Custom Gson to make Retrofit Gson adapter work with Realm objects
 */
@NonNull
@Provides
@Singleton
public static Gson provideGson(@NonNull ListTypeAdapterFactory jsonArrayTypeAdapterFactory,
                               @NonNull HtmlAdapter htmlAdapter,
                               @NonNull StringCapitalizerAdapter stringCapitalizerAdapter) {

    return new GsonBuilder()
            .setExclusionStrategies(new ExclusionStrategy() {
                @Override
                public boolean shouldSkipField(FieldAttributes f) {
                    return f.getDeclaringClass().equals(RealmObject.class);
                }

                @Override
                public boolean shouldSkipClass(Class<?> clazz) {
                    return false;
                }
            })
            .registerTypeAdapterFactory(jsonArrayTypeAdapterFactory)
            .registerTypeAdapter(String.class, htmlAdapter)
            .registerTypeAdapter(String.class, stringCapitalizerAdapter)
            .create();
}
 
Example 16
Project: bigbang   File: GsonRequiredTest.java   Source Code and License 6 votes vote down vote up
@Before
public void setUp() {
  gson = new GsonBuilder()
      .registerTypeHierarchyAdapter(Object.class, new RequiredFieldDeserializer())
      .registerTypeAdapter(LocalDate.class, new MillisecondsLocalDateAdapter())
      .setExclusionStrategies(new ExclusionStrategy() {
        @Override
        public boolean shouldSkipField(FieldAttributes fieldAttributes) {
          return fieldAttributes.getAnnotation(GsonExclude.class) != null;
        }

        @Override
        public boolean shouldSkipClass(Class<?> clazz) {
          return false;
        }
      })
      .create();
}
 
Example 17
Project: bigbang   File: GsonExclusionStrategy.java   Source Code and License 6 votes vote down vote up
/**
 * Retrieves an {@link ExclusionStrategy} that excludes {@link GsonExclude} fields and the classes contained in
 * {@code excludedClasses}.
 *
 * @param strategy the type of the strategy to be retrieved
 * @return the {@link ExclusionStrategy} for the {@code strategy} provided
 */
public ExclusionStrategy getExclusionStrategy(@Nullable GsonExclude.Strategy strategy) {
  return new ExclusionStrategy() {
    @Override
    public boolean shouldSkipField(FieldAttributes fieldAttributes) {
      return shouldSkipFieldFromSerialization(fieldAttributes)
          || (fieldAttributes.getAnnotation(GsonExclude.class) != null
          && (Objects.equals(fieldAttributes.getAnnotation(GsonExclude.class).strategy(), GsonExclude.Strategy.ALL)
          || Objects.equals(fieldAttributes.getAnnotation(GsonExclude.class).strategy(), strategy)));
    }

    @Override
    public boolean shouldSkipClass(Class<?> clazz) {
      return false;
    }
  };
}
 
Example 18
Project: android-client   File: Utils.java   Source Code and License 6 votes vote down vote up
public static Gson getRobolectricGson(GsonBuilder builder) {
    return builder
            .setExclusionStrategies(
                    new ExclusionStrategy() {
                        @Override
                        public boolean shouldSkipField(FieldAttributes f) {
                            return "__robo_data__".equals(f.getName());
                        }

                        @Override
                        public boolean shouldSkipClass(Class<?> clazz) {
                            return false;
                        }
                    }
            ).create();
}
 
Example 19
Project: MyJojoXUtils   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 20
Project: GanWuMei   File: ApiModule.java   Source Code and License 6 votes vote down vote up
@Provides
@Singleton
RestAPI provideRestAPI() {
    Gson gson = new GsonBuilder()
            .setExclusionStrategies(new ExclusionStrategy() {
                @Override
                public boolean shouldSkipField(FieldAttributes f) {
                    return f.getDeclaringClass().equals(RealmObject.class);
                }

                @Override
                public boolean shouldSkipClass(Class<?> clazz) {
                    return false;
                }
            })
            .create();
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(okHttpClient())
            .build();

    return retrofit.create(RestAPI.class);
}
 
Example 21
Project: SteamLib   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 22
Project: 1797-2017   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 23
Project: 1797-2017   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 24
Project: urmusic-desktop   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 25
Project: gaso   File: GsonManager.java   Source Code and License 6 votes vote down vote up
public static Gson getGsonInstance(){
    return new GsonBuilder()
            .setExclusionStrategies(new ExclusionStrategy() {
                @Override
                public boolean shouldSkipField(FieldAttributes f) {
                    return f.getDeclaringClass().equals(RealmObject.class);
                }

                @Override
                public boolean shouldSkipClass(Class<?> clazz) {
                    return false;
                }
            })
            .setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
            .create();
}
 
Example 26
Project: ExamplesAndroid   File: Servicios.java   Source Code and License 6 votes vote down vote up
public Servicios() {

        Gson gson = new GsonBuilder()
                .setExclusionStrategies(new ExclusionStrategy() {
                    @Override
                    public boolean shouldSkipField(FieldAttributes f) {
                        return f.getDeclaringClass().equals(RealmObject.class);
                    }

                    @Override
                    public boolean shouldSkipClass(Class<?> clazz) {
                        return false;
                    }
                })
                .create();


        this.retrofit = new Retrofit.Builder()
                .baseUrl(ip)//
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
        services = retrofit.create(IServices.class);
            //repositoryPhotos.readPostAll();


    }
 
Example 27
Project: FMTech   File: Excluder.java   Source Code and License 6 votes vote down vote up
public final boolean excludeClass(Class<?> paramClass, boolean paramBoolean)
{
  if ((this.version != -1.0D) && (!isValidVersion((Since)paramClass.getAnnotation(Since.class), (Until)paramClass.getAnnotation(Until.class)))) {
    return true;
  }
  if ((!this.serializeInnerClasses) && (isInnerClass(paramClass))) {
    return true;
  }
  if (isAnonymousOrLocal(paramClass)) {
    return true;
  }
  if (paramBoolean) {}
  for (List localList = this.serializationStrategies;; localList = this.deserializationStrategies)
  {
    Iterator localIterator = localList.iterator();
    do
    {
      if (!localIterator.hasNext()) {
        break;
      }
    } while (!((ExclusionStrategy)localIterator.next()).shouldSkipClass$1b2d8b94());
    return true;
  }
  return false;
}
 
Example 28
Project: parsers   File: GsonFactory.java   Source Code and License 6 votes vote down vote up
public static Gson build() {
    GsonBuilder builder = new GsonBuilder();
    builder.addSerializationExclusionStrategy(new ExclusionStrategy() {

        @Override
        public boolean shouldSkipField(FieldAttributes f) {
            return f.getAnnotation(GsonTransient.class) != null;
        }

        @Override
        public boolean shouldSkipClass(Class<?> c) {
            return c.getAnnotation(GsonTransient.class) != null;
        }
    });
    return builder.create();
}
 
Example 29
Project: DisqusSDK-Android   File: capclient.java   Source Code and License 6 votes vote down vote up
/**
 * GSON can parse the data.
 * Note there is a bug in GSON 2.3.1 that can cause it to StackOverflow when working with RealmObjects.
 * To work around this, use the ExclusionStrategy below or downgrade to 1.7.1
 * See more here: https://code.google.com/p/google-gson/issues/detail?id=440
 *
 * @param b gs builder body
 * @return the gbuilder
 */
protected GsonBuilder configBuilder(GsonBuilder b) {

    b.setExclusionStrategies(new ExclusionStrategy() {
        @Override
        public boolean shouldSkipField(FieldAttributes f) {
            return f.getDeclaringClass().equals(RealmObject.class);
        }

        @Override
        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }
    });
    return b;
}
 
Example 30
Project: Royal-Android   File: Rson.java   Source Code and License 6 votes vote down vote up
public static Gson getGson() {
    synchronized (lock) {
        if (gson != null)
            return gson;
        gson = new GsonBuilder()
                .setExclusionStrategies(new ExclusionStrategy() {
                    @Override
                    public boolean shouldSkipField(FieldAttributes f) {
                        return f.getDeclaringClass().equals(RealmObject.class);
                    }

                    @Override
                    public boolean shouldSkipClass(Class<?> clazz) {
                        return false;
                    }
                })
                .create();
        return gson;
    }
}
 
Example 31
Project: listahu-android   File: APIBackend.java   Source Code and License 6 votes vote down vote up
private static Gson getGson() {
    Gson gson = new GsonBuilder()
            .setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
            .setExclusionStrategies(new ExclusionStrategy() {
                @Override
                public boolean shouldSkipField(FieldAttributes f) {
                    return f.getDeclaringClass().equals(RealmObject.class);
                }

                @Override
                public boolean shouldSkipClass(Class<?> clazz) {
                    return false;
                }
            })
            .create();

    return gson;
}
 
Example 32
Project: DroidPlate   File: ApiUtils.java   Source Code and License 6 votes vote down vote up
private static Gson getGson() {
    return new GsonBuilder()
            .setDateFormat(Config.ISO_FORMAT)

            // required for realm.io
            .setExclusionStrategies(new ExclusionStrategy() {
                @Override
                public boolean shouldSkipField(FieldAttributes f) {
                    return f.getDeclaringClass().equals(RealmObject.class);
                }

                @Override
                public boolean shouldSkipClass(Class<?> clazz) {
                    return false;
                }
            })
            .create();
}
 
Example 33
Project: android-http-lib-based-on-volley   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 34
Project: reflect-app   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 35
Project: TheKitchenMod   File: BaseConfig.java   Source Code and License 6 votes vote down vote up
public void writeToFile() throws IOException
{
    BufferedReader reader = new BufferedReader(new FileReader(this.location));
    GsonBuilder builder = new GsonBuilder().setPrettyPrinting().setExclusionStrategies(new ExclusionStrategy()
    {
        @Override
        public boolean shouldSkipField(FieldAttributes f)
        {
            return f.hasModifier(Modifier.PRIVATE);
        }

        @Override
        public boolean shouldSkipClass(Class<?> clazz)
        {
            return false;
        }
    });
    Gson gson = builder.create();
    String json = gson.toJson(this);
    this.location.createNewFile();
    FileWriter writer = new FileWriter(this.location);
    writer.write(json);
    writer.close();
}
 
Example 36
Project: androidsummary   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 37
Project: Edge-Node   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 38
Project: BungeeSigns   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 39
Project: multicraft-api   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}
 
Example 40
Project: StaticMC   File: Excluder.java   Source Code and License 6 votes vote down vote up
public boolean excludeClass(Class<?> clazz, boolean serialize) {
  if (version != Excluder.IGNORE_VERSIONS
      && !isValidVersion(clazz.getAnnotation(Since.class), clazz.getAnnotation(Until.class))) {
    return true;
  }

  if (!serializeInnerClasses && isInnerClass(clazz)) {
    return true;
  }

  if (isAnonymousOrLocal(clazz)) {
    return true;
  }

  List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
  for (ExclusionStrategy exclusionStrategy : list) {
    if (exclusionStrategy.shouldSkipClass(clazz)) {
      return true;
    }
  }

  return false;
}