LoginSignup
0
0

More than 1 year has passed since last update.

Kotlin 今どきよくある JSON リクエストからのパース

Last updated at Posted at 2022-06-18

数年で一気に変わってます、JSONの取り扱い処理。

Gson も Moshi も不要です。

@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
  val contentType = "application/json".toMediaType()
  val json = Json { 
    ignoreUnknownKeys = true
    isLenient = true
  } // *
  return Retrofit.Builder()
    .client(okHttpClient)
    .baseUrl(BASE_URL)
    .addConverterFactory(json.asConverterFactory(contentType))
    .build()
}

Kotlin 内蔵の serialization を使うのが良いでしょう。

👉 Kotlin 今どきよくある JSON リクエストからのパース

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0