我试图获取我拥有的SearchResultView类型的对象列表,并使用Googles Gson库v 2.3将其转换为Json字符串。
以下是相关代码(我通过模仿文档https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html#getAdapter-com.google.gson.reflect.TypeToken-
编写Type typeResults = new TypeToken<List<SearchResultView>>(){}.getType();
String resultsJSON = (new Gson()).toJson(resultsView.getResults(), typeResults);
System.out.println(resultsJSON); //To test output.
打印行打印以下内容:
[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}...
我已经验证了
resultsView.getResults()
返回
类型的对象List<SearchResultView>
并且列表本身不是null和非空。这可能是什么问题?
EDIT(根据要求):SearchResultView是所有'get'和'has'方法的接口。列表中的对象只是一堆实现该接口的对象。