Suppose have the following parameterised data class representing a server response:
public class SocketResponse<T> {
private String responseMessage;
private int responseCode;
private T entity;
}
I know at runtime what type T will be. does moshi support generic type adapter the same way Gson does? With Gson id do the following to parse this.
Type typeA = new TypeToken<SocketResponse<MyResponseA>>(){}.getType();
SocketResponse<MyResponseA> responseA = getResponse("json", typeA);
Type typeB = new TypeToken<SocketResponse<MyResponseB>>(){}.getType();
SocketResponse<MyResponseB> responseB = getResponse("json", typeB);
private String getResponse(Type t){
return gson.fromJson(response, type);
}
I'm mostly using GSON but maybe something like that?