Posted at

Retrofit2でGsonのポリシー設定

More than 1 year has passed since last update.

// Gson

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

//クライアント生成
OkHttpClient client = httpClient.build();
retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(client)
.build();