In my case, when I put a subclass object in a modification request, it is empty in the request body
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);
now i am going through FbUserObject
networkAPI.createUserNew(fbUserObject).subscribe();
then the object becomes empty in the body. see my magazine
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)
I am also viewing this stack stream link. Polymorphism with gson
Should I write my own Gson converter?
source share