List of usage examples for com.google.gson FieldAttributes getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotation)
From source file:br.com.caelum.vraptor.serialization.gson.Exclusions.java
License:Open Source License
@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; }/*from ww w . j a va2 s. c o m*/ } 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()); }
From source file:ch.devmine.javaparser.utils.GsonFactory.java
License:Open Source License
public static Gson build() { GsonBuilder builder = new GsonBuilder(); builder.addSerializationExclusionStrategy(new ExclusionStrategy() { @Override//www.ja v a 2 s . c om 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(); }
From source file:cn.teamlab.wg.framework.struts2.json.JsonSerializerExclusionStrategy.java
License:Apache License
@Override public boolean shouldSkipField(FieldAttributes f) { if (f.getAnnotation(DontExpose.class) != null) { return true; }/*w ww .j a va2 s . c om*/ if (fieldsToExclude == null || fieldsToExclude.isEmpty()) { return false; } for (String fieldToExclude : fieldsToExclude) { if (fieldToExclude == null || fieldToExclude.lastIndexOf('.') == -1) { continue; } String[] split = fieldToExclude.split("\\."); if (split != null && split.length > 1) { String fieldClassName = (split[split.length - 2]).toLowerCase(); String fieldAttrName = (split[split.length - 1]).toLowerCase(); String className = (className(f)).toLowerCase(); String classAttrName = (f.getName()).toLowerCase(); if (className.equals(fieldClassName) && classAttrName.equals(fieldAttrName)) { return true; } } } return fieldsToExclude.contains(f.getName()); }
From source file:co.aurasphere.botmill.fb.internal.util.json.SkipDeserializationAnnotationExclusionStrategy.java
License:Open Source License
public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(SkipDeserialization.class) != null; }
From source file:com.appslandia.common.json.GsonProcessor.java
License:Open Source License
public static GsonBuilder newBuilder() { GsonBuilder builder = new GsonBuilder(); builder.setExclusionStrategies(new ExclusionStrategy() { @Override// ww w. j a v a 2s .c om public boolean shouldSkipField(FieldAttributes attrs) { return attrs.getAnnotation(NotBind.class) != null; } @Override public boolean shouldSkipClass(Class<?> clazz) { return false; } }); builder.registerTypeAdapter(java.util.Date.class, new DateAdapter()); builder.registerTypeAdapter(java.sql.Date.class, new SqlDateAdapter()); builder.registerTypeAdapter(java.sql.Time.class, new SqlTimeAdapter()); builder.registerTypeAdapter(java.sql.Timestamp.class, new SqlDateTimeAdapter()); return builder; }
From source file:com.auxeanne.data.ctrl.RecordExclusionStrategy.java
License:Apache License
@Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(FieldExclusion.class) != null; }
From source file:com.cloud.agent.transport.LoggingExclusionStrategy.java
License:Apache License
@Override public boolean shouldSkipField(FieldAttributes field) { LogLevel level = field.getAnnotation(LogLevel.class); return level != null && !level.value().enabled(_logger); }
From source file:com.cloud.api.response.EmptyFieldExclusionStrategy.java
License:Apache License
@Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { if (fieldAttributes.getAnnotation(Param.class) != null) { return true; }/*from ww w. j av a 2 s . co m*/ return false; }
From source file:com.comapi.internal.network.RestClient.java
License:Open Source License
/** * Create Gson converter for the service. * * @return Gson converter.//www.j ava 2s .c o m */ private Gson createGson() { GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setLenient(). addSerializationExclusionStrategy(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes f) { return f.getAnnotation(SerializedName.class) == null; } @Override public boolean shouldSkipClass(Class<?> clazz) { return false; } }); return gsonBuilder.create(); }
From source file:com.google.belay.server.GsonUtil.java
License:Open Source License
public static GsonBuilder getGsonBuilder() { GsonBuilder gb = new GsonBuilder(); gb.registerTypeAdapter(Capability.class, new CapabilityAdapter()); gb.setExclusionStrategies(new ExclusionStrategy() { @Override//from ww w . j a v a 2 s . co m public boolean shouldSkipField(FieldAttributes attrs) { return attrs.getAnnotation(HideFromClient.class) != null; } @Override public boolean shouldSkipClass(Class<?> cls) { return false; } }); return gb; }