LoginSignup
0
2

More than 5 years have passed since last update.

moshiをkotlinで使ってて、JSONのマッピングがうまくいかないときの対処法

Posted at

moshiのバージョン1.5で、 @Json(name = "ts") val timestamp: String のようにフィールドとプロパティ名を別にして対応づけたんですが、うまくいきませんでした。

どうやら moshi1.5から moshi-kotlin というモジュールが加わったので、それを使わないといけないっぽいです。

Kotlin’s a great language for JSON – Square Corner Blog – Medium

対処法

gradleに compile 'com.squareup.moshi:moshi-kotlin:1.5.0' を追加し、

val moshi = Moshi.Builder()
        .add(KotlinJsonAdapterFactory())
        .build()

としたらうまくいきました。

0
2
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
2