如何通过改造将列表对象作为字段?

时间:2015-05-18 21:42:39

标签: android list post retrofit

服务类

@FormUrlEncoded
@POST("/suggestie/postdossier")
void postDossier(@Field("vraagId")int vraagId,@Field("tekst") String tekst, @Field("gebruikerId") int gebruikerId, @Field("blokken") List<Blok> blokken, Callback<Dossier> callback);

申请类

  private Service createService(Context context) {
    final Gson gson = new GsonBuilder()
            .setDateFormat("dd/MM/yyyy HH:mm:ss") 
            .create();

    return new RestAdapter.Builder()
            .setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setEndpoint(getApplicationContext().getResources().getString(R.string.baseURL))
            .build()
            .create(Service.class);

}

适配器类

public void postDossier(int vraagId, int gebruikerId) {
    Log.e("size van blokken", Integer.toString(blokken.size()));
    getService().postDossier(vraagId, titelDossier, gebruikerId, blokken, this);
}

@Override
public void success(Dossier dossier, Response response) {
    Log.e("postdossier is gelukt!", "");
    Log.e("id dossier", Integer.toString(dossier.getSuggestieId()));
}

@Override
public void failure(RetrofitError error) {
    Log.e("postdossier gefaald", "");
    StringWriter errors = new StringWriter();
    error.printStackTrace(new PrintWriter(errors));
    Log.e("stacktrace",errors.toString());
}

Blok class

public class Blok {
private String Titel;
private int Soort;
private String Inhoud;
private int Position;

public Blok(int position, String titel, int soort, String inhoud) {
    this.Position = position;
    this.Titel = titel;
    this.Soort = soort;
    this.Inhoud = inhoud;
}

public String getTitel() {
    return Titel;
}

public void setTitel(String titel) {
    this.Titel = titel;
}

public int getSoort() {
    return Soort;
}

public void setSoort(int soort) {
    this.Soort = soort;
}

public String getInhoud() {
    return Inhoud;
}

public void setInhoud(String inhoud) {
    this.Inhoud = inhoud;
}

public int getPosition() {
    return Position;
}

public void setPosition(int position) {
    this.Position = position;
}

}

当我发布一个没有任何块的档案时,它没问题。但是当我在列表中有块时,retrofit会返回内部服务器错误。但是我和我的团队检查了服务器端,那里的一切都很好。

我们以错误的方式传递列表吗?我通过谷歌搜索了几个小时,但我没有找到任何答案。

提前致谢!

0 个答案:

没有答案