5
java.lang.IllegalArgumentException: No JsonAdapter for retrofit2.Call<xxxxx.data.adapter.ActivationResponse> (with no annotations)
     Message: Unable to create converter for retrofit2.Call<xxxxx.data.adapter.ActivationResponse>
        for method ActivationService.postActivationPayload

I am getting this error when trying to use Moshi alongside Retrofit for handling a request

package xxxx.data.adapter
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class ActivationResponse(
    var status: String,
    var statusCode: String?,
    var description: String?
)
interface ActivationService { 
@POST("/") // substitute real path
    suspend fun postActivationPayload(@Body activationPayloadPost: ActivationPayloadPost) : Call<ActivationResponse>
}

Here is the activation service im supplying into Retrofit

@JsonClass(generateAdapter = true)
data class ActivationPayloadPost(
    var id: String,
    var status: String?
)

Have I just completely missed a step with working with Moshi and Retrofit? I thought it was supposed to be able to read simple types on its own.

Here is the call for retro

        val BASE_URL = "xxxxx"
        val retrofit = Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(MoshiConverterFactory.create(moshi))
            .build()
        val activationService = retrofit.create(ActivationService::class.java)

I have already tested that my moshi object is able to use moshi.adapter(ActivationPayloadPost::class.java) .toJSON and it IS able to render the output I need, but when running through Retro its giving me this error.

Cody Jones
  • 424
  • 1
  • 5
  • 16
  • I think moshi.adapter() internally creates an adapter if not present already and while you run this it may not be present. And if the adapter isn't present, potentially means annotation hasn't been processed. Can you confirm if you've added--- kapt com.squareup.moshi:moshi-kotlin-codegen:$version_name in your gradle dependencies? – Rashanjyot Singh Arora Apr 22 '21 at 19:21

0 Answers0