5

According to information from official site I added latest depedency and started to develop.

First I created model with data I'm interested:

public class Data{
    String parametr1;
    //geters and setters ommited
}

second step was to add service:

public interface GitHubService {
    @GET("/repos/{owner}/{repo}")
    Call<Data> repoInfos(@Path("user") String owner, @Path("repo") String repo);

    Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.github.com/").build();
}

Third one was to add implementation:

@Service
public class GitHubServiceImpl implements GitHubService {

    final GitHubService gitHubService = GitHubService.retrofit.create(GitHubService.class);

    @Override
    public Call<DetailDto> repoDetails(String owner, String repo) {
        return gitHubService.repoDetails(owner, repo);
    }
}

But there is an error:

java.lang.IllegalArgumentException: Could not locate ResponseBody converter for class model.Data.

Here is full error log trace

degath
  • 1,530
  • 4
  • 31
  • 60
  • Did you checked this out ? https://stackoverflow.com/questions/32343183/retrofit-could-not-locate-converter-for-class-crashing-app – Umair Mohammad Mar 16 '18 at 13:41
  • I'm using maven, not grandle, but maybe it will solve my problem, give me a second to check it. – degath Mar 16 '18 at 13:44

1 Answers1

2

For maven dependency:

<dependency>
    <groupId>com.squareup.retrofit2</groupId>
    <artifactId>converter-gson</artifactId>
    <version><latest-version></version>
</dependency>

For code add a ConverterFactory:

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(Constants.API_BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build();

This should do it.

Mohammad Tabbara
  • 1,438
  • 1
  • 16
  • 31
  • I added this depedency, but there is another problem. – degath Mar 16 '18 at 13:54
  • what kind of a problem – Mohammad Tabbara Mar 16 '18 at 13:54
  • There was an unexpected error (type=Internal Server Error, status=500). retrofit2.OkHttpCall cannot be cast to model.Data. Here is a full error trace: https://pastebin.com/5Z36AQ7B. – degath Mar 16 '18 at 13:58
  • server error I can't help sorry. btw try not to comment many times after your self just edit the previous message unless someone else posted after you. – Mohammad Tabbara Mar 16 '18 at 14:01
  • I changed a return type from Data to Call and now there is no error, but instead of information I wanted it prints: {"canceled":false,"executed":false}. Ok I'll try to edit previous messages. :) – degath Mar 16 '18 at 14:01