com.google.gson.FieldAttributes#getDeclaringClass ( )源码实例Demo

下面列出了com.google.gson.FieldAttributes#getDeclaringClass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: vraptor4   文件: Exclusions.java
@Override
public boolean shouldSkipField(FieldAttributes f) {
	SkipSerialization annotation = f.getAnnotation(SkipSerialization.class);
	if (annotation != null)
		return true;
	
	String fieldName = f.getName();
	Class<?> definedIn = f.getDeclaringClass();

	for (Entry<String, Class<?>> include : serializee.getIncludes().entries()) {
		if (isCompatiblePath(include, definedIn, fieldName)) {
			return false;
		}
	}
	for (Entry<String, Class<?>> exclude : serializee.getExcludes().entries()) {
		if (isCompatiblePath(exclude, definedIn, fieldName)) {
			return true;
		}
	}
	
	Field field = reflectionProvider.getField(definedIn, fieldName);
	return !serializee.isRecursive() && !shouldSerializeField(field.getType());
}
 
@Override
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
    String fieldName = fieldAttributes.getName();
    Class<?> theClass = fieldAttributes.getDeclaringClass();

    return isFieldInSuperclass(theClass, fieldName);
}
 
源代码3 项目: cosmic   文件: SuperclassExclusionStrategy.java
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
    String fieldName = fieldAttributes.getName();
    Class<?> theClass = fieldAttributes.getDeclaringClass();
    Class<?> superclass = theClass.getSuperclass();

    if (this.inheritanceMap.containsKey(theClass)) {
        if (getField(this.inheritanceMap.get(theClass), fieldName) != null) {
            return true;
        }
    }

    this.inheritanceMap.put(superclass, theClass);
    return false;
}
 
源代码4 项目: nfscan   文件: ResultProcessStatusExclusion.java
/**
 * @param f the field object that is under test
 * @return true if the field should be ignored; otherwise false
 */
@Override
public boolean shouldSkipField(FieldAttributes f) {
    if (f.getDeclaringClass() == OCRTransaction.class) {
        return !fieldsOcrTransaction.contains(f.getName());
    } else {
        return false;
    }

}
 
@Test
public void givenExclusionStrategyByClassesAndFields_whenSerializing_thenFollowStrategy() {
    MyClass source = new MyClass(1L, "foo", "bar", new MySubClass(42L, "the answer", "Verbose field which we don't want to be serialized"));
    ExclusionStrategy strategy = new ExclusionStrategy() {
        @Override
        public boolean shouldSkipField(FieldAttributes field) {
            if (field.getDeclaringClass() == MyClass.class && field.getName()
                .equals("other"))
                return true;
            if (field.getDeclaringClass() == MySubClass.class && field.getName()
                .equals("otherVerboseInfo"))
                return true;
            return false;
        }

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

    Gson gson = new GsonBuilder().addSerializationExclusionStrategy(strategy)
        .create();
    String jsonString = gson.toJson(source);

    assertEquals(expectedResult, jsonString);
}
 
源代码6 项目: apkfile   文件: JarFileExclusionStrategy.java
public boolean shouldSkipField(FieldAttributes f) {
    // ZipFiles have a circular reference that makes serializing tricky.
    // JarEntries have a lot of noisy certificate information.
    return (f.getDeclaringClass() == JarFile.class || f.getDeclaringClass() == ZipFile.class || f.getDeclaringClass() == JarEntry.class);
}
 
源代码7 项目: JuniperBot   文件: GsonUtils.java
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
    String fieldName = fieldAttributes.getName();
    Class<?> theClass = fieldAttributes.getDeclaringClass();

    return isFieldInSuperclass(theClass, fieldName);
}