JSON:
[
{
"name": "john",
"surname": "butler",
"age": 18
},
{
"name": "bryan",
"surname": "butler",
"age": 22
},
{
"name": "adam",
"surname": "butler",
"age": 28
}
]
接口:
public interface ListAPI<T> {
@GET(EndPoint.LIST_URL)
void getPersonelList(@Path("name") String name,
Callback<List<Personel>> response);
}
如果类型是如上所述明确定义的,一切都正常工作(Callback&lt; List&lt; Personel&gt;&gt;)但是它在前面的类中定义如下,那么json数据通过Retrofit转换为LinkedTreeMap,这是没想到。
public class PersonelListActivity extends ListeActivity<List<Personel>>{
............
public abstract class ListeActivity<T> extends BaseActivity {
protected ListManager<T> listManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listManager = new ListManager<>(this);
...
public class ListManager<T> extends BaseManager<ListAPI<T>> {
public ListManager(Context context) {
super(context);
}
public void getAritmaList (String name, ResponseListener<T> responseListener){
getBaseActivity().showProgress();
getApi(ListAPI.class).getAritmaList(name, new Retrofit.RetroCallback<>(responseListener));
}
}
public interface ListAPI<T> {
@GET(EndPoint.LIST_URL)
void getAritmaList(@Path("name") String name,
Callback<T> response);
}
正如我所说,如果我明确地将类型定义为List&lt; Personel&gt;在ListAPI界面一切正常。为什么它在将类型移动为通用时不起作用?