Esempio n. 1
0
 public Excluder withModifiers(int... modifiers) {
   Excluder result = clone();
   result.modifiers = 0;
   for (int modifier : modifiers) {
     result.modifiers |= modifier;
   }
   return result;
 }
Esempio n. 2
0
 public Excluder withExclusionStrategy(
     ExclusionStrategy exclusionStrategy, boolean serialization, boolean deserialization) {
   Excluder result = clone();
   if (serialization) {
     result.serializationStrategies = new ArrayList<ExclusionStrategy>(serializationStrategies);
     result.serializationStrategies.add(exclusionStrategy);
   }
   if (deserialization) {
     result.deserializationStrategies =
         new ArrayList<ExclusionStrategy>(deserializationStrategies);
     result.deserializationStrategies.add(exclusionStrategy);
   }
   return result;
 }
Esempio n. 3
0
 /**
  * Configures Gson to apply the passed in exclusion strategy during deserialization. If this
  * method is invoked numerous times with different exclusion strategy objects then the exclusion
  * strategies that were added will be applied as a disjunction rule. This means that if one of the
  * added exclusion strategies suggests that a field (or class) should be skipped then that field
  * (or object) is skipped during its deserialization.
  *
  * @param strategy an exclusion strategy to apply during deserialization.
  * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
  * @since 1.7
  */
 public GsonBuilder addDeserializationExclusionStrategy(ExclusionStrategy strategy) {
   excluder = excluder.withExclusionStrategy(strategy, false, true);
   return this;
 }
Esempio n. 4
0
 /**
  * Configures Gson to apply a set of exclusion strategies during both serialization and
  * deserialization. Each of the {@code strategies} will be applied as a disjunction rule. This
  * means that if one of the {@code strategies} suggests that a field (or class) should be skipped
  * then that field (or object) is skipped during serialization/deserialization.
  *
  * @param strategies the set of strategy object to apply during object (de)serialization.
  * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
  * @since 1.4
  */
 public GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies) {
   for (ExclusionStrategy strategy : strategies) {
     excluder = excluder.withExclusionStrategy(strategy, true, true);
   }
   return this;
 }
Esempio n. 5
0
 /**
  * Configures Gson to exclude inner classes during serialization.
  *
  * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
  * @since 1.3
  */
 public GsonBuilder disableInnerClassSerialization() {
   excluder = excluder.disableInnerClassSerialization();
   return this;
 }
Esempio n. 6
0
 /**
  * Configures Gson to exclude all fields from consideration for serialization or deserialization
  * that do not have the {@link com.google.gson.annotations.Expose} annotation.
  *
  * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
  */
 public GsonBuilder excludeFieldsWithoutExposeAnnotation() {
   excluder = excluder.excludeFieldsWithoutExposeAnnotation();
   return this;
 }
Esempio n. 7
0
 /**
  * Configures Gson to excludes all class fields that have the specified modifiers. By default,
  * Gson will exclude all fields marked transient or static. This method will override that
  * behavior.
  *
  * @param modifiers the field modifiers. You must use the modifiers specified in the {@link
  *     java.lang.reflect.Modifier} class. For example, {@link
  *     java.lang.reflect.Modifier#TRANSIENT}, {@link java.lang.reflect.Modifier#STATIC}.
  * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
  */
 public GsonBuilder excludeFieldsWithModifiers(int... modifiers) {
   excluder = excluder.withModifiers(modifiers);
   return this;
 }
Esempio n. 8
0
 /**
  * Configures Gson to enable versioning support.
  *
  * @param ignoreVersionsAfter any field or type marked with a version higher than this value are
  *     ignored during serialization or deserialization.
  * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
  */
 public GsonBuilder setVersion(double ignoreVersionsAfter) {
   excluder = excluder.withVersion(ignoreVersionsAfter);
   return this;
 }
Esempio n. 9
0
 public Excluder excludeFieldsWithoutExposeAnnotation() {
   Excluder result = clone();
   result.requireExpose = true;
   return result;
 }
Esempio n. 10
0
 public Excluder disableInnerClassSerialization() {
   Excluder result = clone();
   result.serializeInnerClasses = false;
   return result;
 }
Esempio n. 11
0
 public Excluder withVersion(double ignoreVersionsAfter) {
   Excluder result = clone();
   result.version = ignoreVersionsAfter;
   return result;
 }
 static boolean excludeField(Field f, boolean serialize, Excluder excluder) {
   return !excluder.excludeClass(f.getType(), serialize) && !excluder.excludeField(f, serialize);
 }