我正在编写以下代码,将我的JSON sting转换为我的对象列表。
List<MyObject> myResponse = new ArrayList<MyObject>();
myResponse = new ObjectMapper().readValue(responseString, new TypeReference<List<MyObject>>(){});
但是eclipse正在抱怨以下错误:
The method readValue(String, Class<T>) in the type ObjectMapper is not applicable for the arguments (String, new TypeReference<List<MyObject>>(){})
可能出现什么错误?
答案 0 :(得分:6)
问题是导入TypeReference。我正在使用
import com.fasterxml.jackson.core.type.TypeReference
而不是
import org.codehaus.jackson.type.TypeReference
答案 1 :(得分:0)
For me the issue was with import of ObjectMapper. I was using
import com.fasterxml.jackson.core.type.ObjectMapper
instead of
import org.codehaus.jackson.type.ObjectMapper