Fuel

https://github.com/kittinunf/Fuel

通信処理

// 非同期で実行
Fuel.get("url").responseObject(Foo.Deserializer()) { request, response, result ->
    val (data, error) = result
    error?.let {
        print(it.message)
    }
    data?.let {
        // 成功時の処理
    }
}

レスポンス

data class Foo(
        var bar: String
) {
  class Deserializer : ResponseDeserializable<List<Foo>> {
       override fun deserialize(content: String): <List<Foo>>? {
          // snake_caseから変換
          val gson = GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create()
          return gson.fromJson(content, List<Foo>::class.java)
       }
   }

}

参考

https://www.youtube.com/watch?v=14RgaptG510

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.