Example usage for com.google.gson FieldAttributes getAnnotation

List of usage examples for com.google.gson FieldAttributes getAnnotation

Introduction

In this page you can find the example usage for com.google.gson FieldAttributes getAnnotation.

Prototype

public <T extends Annotation> T getAnnotation(Class<T> annotation) 

Source Link

Document

Return the T annotation object from this field if it exist; otherwise returns null .

Usage

From source file:org.artemis.toolkit.common.ignorestrategy.java

License:Apache License

@Override
public boolean shouldSkipField(FieldAttributes f) {
    return f.getAnnotation(ignore.class) != null;
}

From source file:org.cellcore.code.shared.GsonAnnotationExclusionStrategy.java

License:Apache License

public boolean shouldSkipField(FieldAttributes f) {
    boolean value = f.getAnnotation(GsonExclude.class) != null;
    return value;
}

From source file:org.chaos.fx.cnbeta.net.CnBetaApiHelper.java

License:Apache License

public static void initialize() {
    sMobileApi = new Retrofit.Builder().baseUrl(MobileApi.BASE_URL).addConverterFactory(
            GsonConverterFactory.create(new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
                @Override/*ww  w  .j  a  va 2s  .  c om*/
                public boolean shouldSkipField(FieldAttributes f) {
                    return f.getAnnotation(SerializedName.class) == null;
                }

                @Override
                public boolean shouldSkipClass(Class<?> clazz) {
                    return false;
                }
            }).create())).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build()
            .create(MobileApi.class);

    sMWebApi = new Retrofit.Builder().baseUrl(MWebApi.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build().create(MWebApi.class);

    OkHttpClient okHttpClient = CnBetaHttpClientProvider.newCnBetaHttpClient();

    sWebApi = new Retrofit.Builder().baseUrl(WebApi.HOST_URL).client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build().create(WebApi.class);

    sCookieDownloader = new OkHttp3Downloader(okHttpClient);
}

From source file:org.netxms.websvc.json.JsonTools.java

License:Open Source License

/**
 * Create JSON representation for given object
 * //from   w  ww.j av a 2  s.  c  o  m
 * @param object object to serialize
 * @return JSON code
 */
public static String jsonFromObject(Object object) {
    if (object instanceof JsonObject)
        return ((JsonObject) object).toString();
    if (object instanceof ResponseContainer)
        return ((ResponseContainer) object).toJson();

    GsonBuilder builder = new GsonBuilder();
    builder.setPrettyPrinting(); // FIXME: remove for production
    builder.registerTypeAdapter(Date.class, new DateAdapter());
    builder.registerTypeAdapter(InetAddress.class, new InetAddressAdapter());
    builder.registerTypeAdapter(InetAddressEx.class, new InetAddressExAdapter());
    builder.registerTypeAdapter(MacAddress.class, new MacAddressAdapter());
    builder.setExclusionStrategies(new ExclusionStrategy() {
        @Override
        public boolean shouldSkipField(FieldAttributes f) {
            return f.getAnnotation(Internal.class) != null;
        }

        @Override
        public boolean shouldSkipClass(Class<?> c) {
            return c.isAnnotationPresent(Internal.class);
        }
    });
    return builder.create().toJson(object);
}

From source file:org.pascani.dsl.dbmapper.typeadapters.TransientExclusionStrategy.java

License:Open Source License

@Override
public boolean shouldSkipField(FieldAttributes field) {
    return field.getAnnotation(Transient.class) != null;
}

From source file:pl.datamatica.traccar.api.dtos.AnnotationExclusionStrategy.java

License:Open Source License

@Override
public boolean shouldSkipField(FieldAttributes fa) {
    return fa.getAnnotation(JsonIgnore.class) != null;
}

From source file:pl.softech.gw.json.JsonExclusionStrategy.java

License:Apache License

@Override
public boolean shouldSkipField(FieldAttributes f) {
    return f.getAnnotation(JsonExclude.class) != null;
}

From source file:se.sperber.cryson.serialization.UserTypeExclusionStrategy.java

License:Apache License

public boolean shouldSkipField(FieldAttributes f) {
    // TODO: move to ReflectionHelper & cache there?
    return f.getAnnotation(org.hibernate.annotations.Type.class) != null;
}

From source file:uk.ac.horizon.aestheticodes.server.ExperienceParser.java

License:Open Source License

public static Gson createParser() {
    GsonBuilder build = new GsonBuilder();
    build.registerTypeAdapter(new TypeToken<Map<String, Marker>>() {
    }.getType(), new MarkerMapAdapter());
    build.addSerializationExclusionStrategy(new ExclusionStrategy() {
        @Override/*  ww w .java  2  s . c o  m*/
        public boolean shouldSkipField(FieldAttributes f) {
            final JsonIgnore ignore = f.getAnnotation(JsonIgnore.class);
            return ignore != null;
        }

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

From source file:util.PodbaseUtil.java

License:MIT License

public static Gson getGsonExcludesGsonTransient() {
    Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
        @Override//from  w  w w.j a va 2 s.c  om
        public boolean shouldSkipClass(Class<?> arg0) {
            return false;
        }

        @Override
        public boolean shouldSkipField(FieldAttributes field) {
            GsonTransient annotation = field.getAnnotation(GsonTransient.class);
            return annotation != null;
        }
    }).registerTypeAdapter(ImageAttribute.class, new ImageAttributeAdaptor())
            .registerTypeAdapter(AccessType.class, new AccessTypeAdaptor())
            .registerTypeAdapter(VirtualAccessType.class, new VirtualAccessTypeAdaptor())
            .registerTypeAdapter(Activation.class, new ActivationAdaptor())
            .registerTypeAdapter(Date.class, new DateAdaptor()).create();
    return gson;
}