rharter / ktor-moshi

Ktor feature that adds Moshi JSON serialization support
Apache License 2.0
82 stars 6 forks source link

Crash: Using blocking primitives on this dispatcher is not allowed #11

Open 1gravity opened 3 years ago

1gravity commented 3 years ago

MoshiConverter crashes with: "Using blocking primitives on this dispatcher is not allowed. Consider using async channel instead or use blocking primitives in withContext(Dispatchers.IO) instead."

What you need to do is (In the MoshiConverter):

    return withContext(Dispatchers.IO) {
      val source = channel.toInputStream().source().buffer()
      val type = request.type
      moshi.adapter(type.javaObjectType).fromJson(source)
    }