java - 使用 Retrofit 在 POST 请求中发送数组列表会发送带有内存地址的对象,而不是发送值

标签 java android retrofit

我有一个类:

public class PetModel{
    Serialized("cat")
    String cat;
    Serialized("dog")
    String dog;
    // getters and setters
}

当我像这样使用改造进行 POST 时:

@FormUrlEncoded
@POST("/pet/{id}")
Pets postPets(@Path("id") String id,@Field("pets") ArrayList<PetModel> pets);

在日志中我看到发送 <package_name>.PetModel@cc49e70 的请求而不是发送值本身。我做错了什么?

最佳答案

请尝试以下方法,也许你会得到解决方案

PrintWriter out = response.getWriter();
List<Countries> country = new ArrayList<Countries>();
country = FetchData.getAllCountries();
JSONObject js = new JSONObject();
js.put("countries", country); // make sure the Country class overrides toString()

// set the response content-type
response.setContentType("application/json");

// writing the json-array to the output stream
out.print(js.toJSONString());
out.flush();

关于java - 使用 Retrofit 在 POST 请求中发送数组列表会发送带有内存地址的对象,而不是发送值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45837848/

相关文章:

java - 从应用程序服务器监听端口

java - 我用这个 ant 构建文件创建 Web 服务客户端做错了什么?

android - Flutter Assets 中的多分辨率背景图像

android - Crashlytics 连接被拒绝 - 无法连接到无法连接到 api.crashlytics.com

android - 房间改造 Dagger2 MVP : Error: cannot find symbol variable DaggerAppComponent

java - 使用正则表达式处理 ^ 符号以获取多项式的幂

java - 在 InputStream 的 read() 中阻止 I/O

android - 删除下载的机器人 jar

android - 为什么我无法在我的 Android 应用程序中使用 Retrofit 在 POST 请求中成功发送 JSON

java - 将 GSON 序列化日期从 json 字符串转换为 java.util.date