小编Ank*_*rya的帖子

无法将Subclass对象转换为使用GsonConverterFactory在Retrofit 2.0中请求body json

在我的情况下,当我将子类对象放入改装请求时,它在请求体中变为空白

interface User{ // my super interface
} 

class FbUser implements User{  // my sub class
   public String name;
   public String email;
}

interface APIInterface{
    @POST(APIConstants.LOGIN_URL)
    Observable<LoginAPIResponse> createUserNew(@Body User user);
}



Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create(new Gson()))
                .addCallAdapterFactory(RxErrorHandlingCallAdapterFactory.create())
                .client(okHttpClient)
                .build();

    APIInterface    networkAPI = retrofit.create(APIInterface.class);
Run Code Online (Sandbox Code Playgroud)

现在我过世了 FbUserObject

networkAPI.createUserNew(fbUserObject).subscribe();
Run Code Online (Sandbox Code Playgroud)

然后物体在身体上变成空白.看我的日志

 D/OkHttp: Content-Type: application/json; charset=UTF-8
D/OkHttp: Content-Length: 2
D/OkHttp: Accept: application/json
D/OkHttp: TT-Mobile-Post: post
D/OkHttp: {}
D/OkHttp: --> END POST (2-byte body)
Run Code Online (Sandbox Code Playgroud)

我也经历了这个stackover流程链接Polymorphism与gson

我应该写自己的Gson转换器吗?

java android gson rx-java retrofit2

6
推荐指数
1
解决办法
1388
查看次数

更新支持库的最佳方法

直到现在(2017年11月30日)谷歌已发布Android支持lib版本27.0.2和Android Api版本27(预览版).现在我的应用程序有Target version 25,Build tool version 25.0.3Compile sdk version 25.我打算更新我的支持库以及编译sdk版本到26.所以我的问题是
1.支持lib版本是否与android Api版本相关意味着我没有将android api更新为27因为它在预览中所以我应该使用支持lib 26.xx或27.xx(这是最新的).
2.我应该使用哪种构建工具版本

android android-appcompat android-support-library android-studio android-gradle-plugin

3
推荐指数
1
解决办法
9131
查看次数