在我的问题question
中添加我的JSON
{
"status" : "SUCCESS",
"count" : 1,
"type" : "InfraNameModel",
"results" : [{
"infraName" : "TEST1"
}
]
}
IBeanFactory
public interface IBeanFactory extends AutoBeanFactory {
IBeanFactory INSTANCE = GWT.create(IBeanFactory.class);
AutoBean<InfraNameModel> infraName();
AutoBean<InfraNameListModel> results();
}
InfraNameListModel
public interface InfraNameListModel {
List<InfraNameModel> getResults();
void setResults(List<InfraNameModel> infraNameModel);
}
InfraNameListModelImpl
public class InfraNameListModelImpl implements InfraNameListModel {
private List<InfraNameModel> results;
@Override
public List<InfraNameModel> getResults() {
return results;
}
@Override
public void setResults(List<InfraNameModel> results) {
this.results = results;
}
}
InfraNameModel
public interface InfraNameModel {
String getInfraName();
void setInfraName(String infraName);
}
InfraNameModelImpl
public class InfraNameModelImpl implements InfraNameModel {
private String infraName;
@Override
public String getInfraName() {
return infraName;
}
@Override
public void setInfraName(String infraName) {
this.infraName = infraName;
}
}
我如何使用
InfraNameListModel infraNameListModel = beanFactory.deserializeFromJson(jsonParser.getResultsJSON());
logger.info(infraNameListModel.toString());
List<InfraNameModel> infraNameModelList = infraNameListModel. getResults();
logger.info(infraNameModelList.toString());
InfraNameModel infraNameModelImpl = infraNameModelList.get(0);
logger.info(infraNameModelImpl.toString());
一切正常。但我有一个问题。
在&#34;结果&#34;可以有不同类型的bean。如何为所有类型制作通用列表?
我试试
public interface ResultsModel<T> {
List<T> getResults();
void setResults(List<T> infraNameModel);
}
InfraNameResultsModelImpl
public class InfraNameResultsModelImpl implements ResultsModel<InfraNameModel> {
private List<InfraNameModel> results;
@Override
public List getResults() {
return results;
}
@Override
public void setResults(List infraNameModel) {
this.results = results;
}
}
但错误=(
是否可以为所有类型的结果实施公共列表?
ResultsModel<InfraNameModel> resultsModel = beanFactory.deserializeFromJson(ResultsModel.class,jsonParser.getResultsJSON());
logger.info(resultsModel.toString());
List<InfraNameModel> infraNameModelList = resultsModel. getResults();
logger.info(infraNameModelList.toString());
InfraNameModel infraNameModelImpl = infraNameModelList.get(0);
logger.info(infraNameModelImpl.toString());