Java Code Examples for com.google.gson.GsonBuilder#setFieldNamingPolicy()

The following examples show how to use com.google.gson.GsonBuilder#setFieldNamingPolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResolveNuance.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
public void unpack(@NonNull final JSONObject payload) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "unpacking");
    }

    final GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);

    final Gson gson = builder.create();
    nluNuance = gson.fromJson(payload.toString(), new TypeToken<NLUNuance>() {
    }.getType());

    new NLUCoerce(getNLUNuance(), getContext(), getSupportedLanguage(), getVRLocale(), getTTSLocale(),
            getConfidenceArray(), getResultsArray()).coerce();
}
 
Example 2
Source File: ResolveSaiy.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
public void unpack(@NonNull final JSONObject payload) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "unpacking");
    }

    final GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);

    final Gson gson = builder.create();
    nluSaiy = gson.fromJson(payload.toString(), new TypeToken<NLUSaiy>() {
    }.getType());

    new NLUCoerce(getNLUSaiy(), getContext(), getSupportedLanguage(), getVRLocale(), getTTSLocale(),
            getConfidenceArray(), getResultsArray()).coerce();
}
 
Example 3
Source File: ApnsPushService.java    From p2 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ApnsPushService() {
    final GsonBuilder gsonBuilder = new GsonBuilder();
    Adapter.register(gsonBuilder);
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES);

    final SSLContext sslContext;
    try {
        sslContext = SSLContext.getInstance("TLSv1.2");
        sslContext.init(new KeyManager[]{new ClientCertificateKeyManager()}, null, null);
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new AssertionError(e);
    }

    final X509TrustManager trustManager = TrustManager.getDefault();
    if (trustManager == null) {
        throw new AssertionError("Unable to find default trust manager");
    }
    final OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder();
    okHttpBuilder.sslSocketFactory(sslContext.getSocketFactory(), trustManager);

    ApnsConfiguration configuration = Configuration.getInstance().getApnsConfiguration();

    final Retrofit.Builder retrofitBuilder = new Retrofit.Builder();
    if (configuration != null && configuration.isSandbox()) {
        retrofitBuilder.baseUrl(SANDBOX_BASE_URL);
    } else {
        retrofitBuilder.baseUrl(BASE_URL);
    }
    retrofitBuilder.addConverterFactory(GsonConverterFactory.create(gsonBuilder.create()));
    retrofitBuilder.client(okHttpBuilder.build());

    final Retrofit retrofit = retrofitBuilder.build();

    this.httpInterface = retrofit.create(ApnsHttpInterface.class);
}
 
Example 4
Source File: FcmPushService.java    From p2 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public FcmPushService() {
    final GsonBuilder gsonBuilder = new GsonBuilder();
    Adapter.register(gsonBuilder);
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);

    final Retrofit.Builder retrofitBuilder = new Retrofit.Builder();
    retrofitBuilder.baseUrl(BASE_URL);
    retrofitBuilder.addConverterFactory(GsonConverterFactory.create(gsonBuilder.create()));

    final Retrofit retrofit = retrofitBuilder.build();

    this.httpInterface = retrofit.create(FcmHttpInterface.class);
}
 
Example 5
Source File: GsonUtils.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
     * Create the standard {@link Gson} configuration
     *
     * @param serializeNulls whether nulls should be serialized
     * @return created gson, never null
     */
    public static final Gson createGson(final boolean serializeNulls) {
        final GsonBuilder builder = new GsonBuilder();
//		builder.registerTypeAdapter(Date.class, new DateFormatter());
//		builder.registerTypeAdapter(Event.class, new EventFormatter());
        builder.setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES);
        if (serializeNulls)
            builder.serializeNulls();
        return builder.create();
    }
 
Example 6
Source File: ApiModule.java    From mockstar with MIT License 5 votes vote down vote up
@Provides
@Singleton
Gson provideGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    return gsonBuilder.create();
}
 
Example 7
Source File: DataModule.java    From Movies-Android-Kata with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
Gson provideGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    return gsonBuilder.create();
}
 
Example 8
Source File: BaseRetrofitWebClientTestCase.java    From DebugRank with Apache License 2.0 5 votes vote down vote up
protected Retrofit getRetrofit()
{
    final Interceptor fakeIntercepter = new Interceptor()
    {
        @Override
        public Response intercept(Chain chain) throws IOException
        {
            Response response = null;

            fullQuery = chain.request().url().toString();

            String responseString = "insert json here if needed";

            response = new Response.Builder()
                    .code(200)
                    .message(responseString)
                    .request(chain.request())
                    .protocol(Protocol.HTTP_1_0)
                    .body(ResponseBody.create(MediaType.parse("application/json"), responseString.getBytes()))
                    .addHeader("content-type", "application/json")
                    .build();

            return response;
        }
    };

    final OkHttpClient client = new OkHttpClient.Builder().addInterceptor(fakeIntercepter).build();

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    Gson gson = gsonBuilder.create();

    return new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(client)
            .baseUrl("http://www.google.com")
            .build();
}
 
Example 9
Source File: NetModule.java    From DebugRank with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
Gson provideGson()
{
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    return gsonBuilder.create();
}
 
Example 10
Source File: NetModule.java    From Weather2016 with MIT License 5 votes vote down vote up
@Provides
@Singleton
Gson provideGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    return gsonBuilder.create();
}
 
Example 11
Source File: NetworkModule.java    From Retrofit2RxjavaDemo with Apache License 2.0 5 votes vote down vote up
@Provides
@AppScope
Gson provideGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY);
    return gsonBuilder.create();
}
 
Example 12
Source File: NetModule.java    From android-mvp-starter with MIT License 5 votes vote down vote up
@Provides
@Singleton
Gson provideGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    return gsonBuilder.create();
}
 
Example 13
Source File: GsonFactory.java    From gerrit-rest-java-client with Apache License 2.0 5 votes vote down vote up
public static Gson create() {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Date.class, new DateDeserializer());
    builder.registerTypeAdapter(Date.class, new DateSerializer());
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    return builder.create();
}
 
Example 14
Source File: GsonJsonEngine.java    From lastaflute with Apache License 2.0 4 votes vote down vote up
protected void setupFieldPolicy(GsonBuilder builder) {
    final JsonFieldNaming naming = option.getFieldNaming().orElse(getDefaultFieldNaming());
    builder.setFieldNamingPolicy(deriveFieldNamingPolicy(naming));
}