当前位置: 首页>>代码示例>>Java>>正文


Java FieldAttributes类代码示例

本文整理汇总了Java中com.google.gson.FieldAttributes的典型用法代码示例。如果您正苦于以下问题:Java FieldAttributes类的具体用法?Java FieldAttributes怎么用?Java FieldAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FieldAttributes类属于com.google.gson包,在下文中一共展示了FieldAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGsonBuilder

import com.google.gson.FieldAttributes; //导入依赖的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: WebApi

import com.google.gson.FieldAttributes; //导入依赖的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

示例3: makeGsonForRealm

import com.google.gson.FieldAttributes; //导入依赖的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

示例4: addFlagToObject

import com.google.gson.FieldAttributes; //导入依赖的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

示例5: provideGson

import com.google.gson.FieldAttributes; //导入依赖的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

示例6: setUp

import com.google.gson.FieldAttributes; //导入依赖的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

示例7: getExclusionStrategy

import com.google.gson.FieldAttributes; //导入依赖的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

示例8: getRobolectricGson

import com.google.gson.FieldAttributes; //导入依赖的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

示例9: shouldSkipField

import com.google.gson.FieldAttributes; //导入依赖的package包/类
public boolean shouldSkipField(final FieldAttributes f) {
    final Param param = f.getAnnotation(Param.class);
    if (param != null) {
        final RoleType[] allowedRoles = param.authorized();
        if (allowedRoles.length > 0) {
            boolean permittedParameter = false;
            final Account caller = CallContext.current().getCallingAccount();
            for (final RoleType allowedRole : allowedRoles) {
                if (allowedRole.getValue() == caller.getType()) {
                    permittedParameter = true;
                    break;
                }
            }
            if (!permittedParameter) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:21,代码来源:ApiResponseGsonHelper.java

示例10: provideRestAPI

import com.google.gson.FieldAttributes; //导入依赖的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

示例11: getGsonInstance

import com.google.gson.FieldAttributes; //导入依赖的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

示例12: Servicios

import com.google.gson.FieldAttributes; //导入依赖的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

示例13: shouldSkipField

import com.google.gson.FieldAttributes; //导入依赖的package包/类
public boolean shouldSkipField(FieldAttributes f)
{
	if (this.excludeFields == null)
	{
		return false;
	}

	for (String field : this.excludeFields)
	{
		if (field.equals(f.getName()))
		{
			return true;
		}
	}
	return false;
}
 
开发者ID:ChenAt,项目名称:Translation,代码行数:17,代码来源:MyGsonExclusionStrategy.java

示例14: build

import com.google.gson.FieldAttributes; //导入依赖的package包/类
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();
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:17,代码来源:GsonFactory.java

示例15: configBuilder

import com.google.gson.FieldAttributes; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:jjhesk,项目名称:DisqusSDK-Android,代码行数:25,代码来源:capclient.java


注:本文中的com.google.gson.FieldAttributes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。