【发布时间】:2016-03-22 03:25:59
【问题描述】:
我在 android 中使用 Retrofit,而 GsonConverterFactory 是转换器。
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://xxxxxxx.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
我想发送带有正文的 POST 请求。
public class MasterRequest
{
}
public class User extends MasterRequest
{
@SerializedName("email")
public String email = null;
}
@POST("{path}")
Call<MasterResponse> registerUser(@Path("path") String path, @Body MasterRequest masterRequest);
path 是附加基本 URL 的 URL。
当我在父类引用(MasterRequest)中发送子类(“User”)对象时,转换器显示为空 json; “{}”。
但是当我将用户类对象发送到下面的 registerUser 方法时,它工作正常。
@POST("{path}")
Call<MasterResponse> registerUser(@Path("path") String path, @Body User user);
如何在父类实例中发送子类对象来生成请求体?
【问题讨论】:
标签: android json gson retrofit