改造停止工作,总是抛出错误"无法创建转换器"

时间:2016-07-11 16:25:12

标签: android retrofit2

我设法让retrofit2工作了一段时间。我成功地使用了@POST和@GET。

@POST("incidents")
Call<CallbackRequest> sendCallbackReport(@Body CallbackRequest callbackRequest, @Query("api_key") String apiKey, @Query("device_id") String deviceId);
@GET("articles")
Call<Articles> getArticles(@Query("api_key") String apiKey);

但现在由于java.lang.IllegalArgumentException: Unable to create converter for...

而停止了工作

我不知道我的项目发生了什么变化,所以突然停止了工作。我的配置如下所示:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'

}

使用它:

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

我同时可以将其缩小到某个POST请求:

@POST("incidents")
Call<GeneralRequest> sendGeneralRequest(@Body GeneralRequest generalRequest, @Query("api_key") String apiKey, @Query("device_id") String deviceId);

使用相应的模型:

public class GeneralRequest extends BaseRequest  {

private String subject;

private String notes;
private int serviceId;

public GeneralRequest(String company, String name, String phone, String email, String subject, String notes, int serviceId, int companyId, boolean emailNotification) {
    super(company, name, phone, email, companyId, notes, emailNotification);
    this.subject = subject;
    this.notes = notes;
    this.serviceId = serviceId;

    HashMap<String,Object> incident = new HashMap<String, Object>();
    incident.put("type","GeneralRequest");
    this.setIncident(incident);
}

public GeneralRequest(String company, String name, String phone, String email, String subject, String notes, int companyId, boolean emailNotification) {
    super(company, name, phone, email, companyId, notes, emailNotification);
    this.subject = subject;
    this.notes = notes;

    HashMap<String,Object> incident = new HashMap<String, Object>();
    incident.put("type","GeneralRequest");
    this.setIncident(incident);
}

public String getSubject() {
    return subject;
}

public void setSubject(String subject) {
    this.subject = subject;
}

public String getMessage() {
    return notes;
}

public void setMessage(String message) {
    this.notes = message;
}

public int getServiceId() {
    return serviceId;
}

public void setServiceId(int serviceId) {
    this.serviceId = serviceId;
}

这里可能出现什么问题?任何帮助都非常感谢。

0 个答案:

没有答案