當前位置: 首頁>>代碼示例>>Java>>正文


Java ExclusionStrategy類代碼示例

本文整理匯總了Java中com.google.gson.ExclusionStrategy的典型用法代碼示例。如果您正苦於以下問題:Java ExclusionStrategy類的具體用法?Java ExclusionStrategy怎麽用?Java ExclusionStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExclusionStrategy類屬於com.google.gson包,在下文中一共展示了ExclusionStrategy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getGsonBuilder

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
/**
 * 構建通用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;
}
 
開發者ID:DataAgg,項目名稱:DaUtil,代碼行數:24,代碼來源:WJsonUtils.java

示例2: createRouteBuilder

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
@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");
        }
    };
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:GsonMarshalExclusionTest.java

示例3: excludeClass

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
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;
}
 
開發者ID:appcelerator-archive,項目名稱:ti.box,代碼行數:24,代碼來源:Excluder.java

示例4: WebApi

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
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();
}
 
開發者ID:jdupl,項目名稱:lancoder,代碼行數:17,代碼來源:WebApi.java

示例5: excludeClass

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:Excluder.java

示例6: makeGsonForRealm

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:20,代碼來源:GsonProvider.java

示例7: excludeClass

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:Excluder.java

示例8: addFlagToObject

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
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);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:18,代碼來源:MCRPIRegistrationService.java

示例9: provideGson

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:Plastix,項目名稱:Forage,代碼行數:28,代碼來源:OkApiModule.java

示例10: setUp

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
@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();
}
 
開發者ID:xmartlabs,項目名稱:bigbang,代碼行數:19,代碼來源:GsonRequiredTest.java

示例11: getExclusionStrategy

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
/**
 * 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;
    }
  };
}
 
開發者ID:xmartlabs,項目名稱:bigbang,代碼行數:24,代碼來源:GsonExclusionStrategy.java

示例12: getRobolectricGson

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
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();
}
 
開發者ID:barracksiot,項目名稱:android-client,代碼行數:17,代碼來源:Utils.java

示例13: provideRestAPI

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
@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);
}
 
開發者ID:Dimon94,項目名稱:GanWuMei,代碼行數:26,代碼來源:ApiModule.java

示例14: getGsonInstance

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
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();
}
 
開發者ID:Gaso-UFS,項目名稱:gaso,代碼行數:17,代碼來源:GsonManager.java

示例15: Servicios

import com.google.gson.ExclusionStrategy; //導入依賴的package包/類
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();


    }
 
開發者ID:David-Hackro,項目名稱:ExamplesAndroid,代碼行數:27,代碼來源:Servicios.java


注:本文中的com.google.gson.ExclusionStrategy類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。