All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gocardless.http.GsonFactory Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package com.gocardless.http;

import static com.google.gson.FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

final class GsonFactory {
    private GsonFactory() {
        // blank to prevent instantiation
    }

    static Gson build() {
        return new GsonBuilder().setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES)
                .addSerializationExclusionStrategy(new PathParamExclusionStrategy())
                .registerTypeAdapterFactory(new GCEnumTypeAdapterFactory()).create();
    }

    private static class PathParamExclusionStrategy implements ExclusionStrategy {
        @Override
        public boolean shouldSkipField(FieldAttributes f) {
            return f.getAnnotation(PathParam.class) != null;
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy