How to add a converter (GSON) to retrofit in netbeans for javaFX project?

1

As you already read above, I am trying to configure a converter to retrofit , all this in netbeans, for android it will be used and there it will be added with Gradle and in netbeans with maven but at the time of doing the class where I set retrofit and I'm going to add GSON as a converter, netbeans does not recognize the instruction even if I add the import :

import retrofit2.converter.gson.GsonConverterFactory;

I get the following message

  

package retrofit2.converter.gson does not exist

It is supposed to exist because I use the same version of retrofit that I used in android 2.3.0

This is my code

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import okhttp3.Credentials;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; //marca el error


/**
 *
 * @author 
 */
public class ConfigRetrofit {

    private static final String url = "mi url";

    private static final OkHttpClient.Builder httpClient = new OkHttpClient.Builder();


     private static Retrofit.Builder builder =
            new Retrofit.Builder()
                    .baseUrl(url)
                    .addConverterFactory(GsonConverterFactory.create())
                   ;

and on the side of my api with which I'm trying to connect is all right, what does not allow me to move forward is this, beware someone can help me, thank you in advance

    
asked by JesusSh 21.04.2018 в 20:49
source

1 answer

1

It gives you that error because the library that uses the converter does not exist in that library is in com.squareup.retrofit2 you can download jar in this link

  • You can add it with maven in this way:

    <dependency>
    <groupId>com.squareup.retrofit2</groupId>
    <artifactId>converter-gson</artifactId>
    <version>latest.version</version>
    </dependency>
    
  • With gradle you can add it like this:

    compile 'com.squareup.retrofit2:converter-gson:latest.version' 
    
answered by 23.04.2018 / 17:38
source