"unable to create converter for my class in android retrofit library" Code Answer


prior to 2.0.0, the default converter was a gson converter, but in 2.0.0 and later the default converter is responsebody. from the docs:

by default, retrofit can only deserialize http bodies into okhttp's responsebody type and it can only accept its requestbody type for @body.

in 2.0.0+, you need to explicitly specify you want a gson converter:

retrofit retrofit = new retrofit.builder()
    .baseurl("**sample base url here**")

you will also need to add the following dependency to your gradle file:

compile 'com.squareup.retrofit2:converter-gson:2.1.0'

use the same version for the converter as you do for your retrofit. the above matches this retrofit dependency:

compile ('com.squareup.retrofit2:retrofit:2.1.0')

also, note as of writing this, the retrofit docs are not completely updated, which is why that example got you into trouble. from the docs:

note: this site is still in the process of being expanded for the new 2.0 apis.

By sanscore on August 10 2022

Answers related to “unable to create converter for my class in android retrofit library”

Only authorized users can answer the Search term. Please sign in first, or register a free account.