ReadValue () doesn't work with TypeReference
I am writing the following code to convert my JSON sting to a list of my object.
List<MyObject> myResponse = new ArrayList<MyObject>();
myResponse = new ObjectMapper().readValue(responseString, new TypeReference<List<MyObject>>(){});
But eclipse is complaining about the following error:
The method readValue(String, Class<T>) in the type ObjectMapper is not applicable for the arguments (String, new TypeReference<List<MyObject>>(){})
What could be the mistake?
+3
αƞjiβ
source
to share
2 answers
The problem was with the TypeReference import. I used
import com.fasterxml.jackson.core.type.TypeReference
instead
import org.codehaus.jackson.type.TypeReference
+6
αƞjiβ
source
to share
For me, the problem was importing ObjectMapper. I used
import com.fasterxml.jackson.core.type.ObjectMapper
instead
import org.codehaus.jackson.type.ObjectMapper
0
akritaag
source
to share