Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

readValue() no working with TypeReference

Tags:

json

jackson

I am writing following code to convert my JSON sting to list of my object.

List<MyObject> myResponse = new ArrayList<MyObject>();
myResponse = new ObjectMapper().readValue(responseString, new TypeReference<List<MyObject>>(){});

But eclipse is complaining with following error:

The method readValue(String, Class<T>) in the type ObjectMapper is not applicable for the arguments (String, new TypeReference<List<MyObject>>(){})

What can be possible error?

like image 949
αƞjiβ Avatar asked Sep 06 '25 03:09

αƞjiβ


2 Answers

Issue was with import of TypeReference. I was using

import com.fasterxml.jackson.core.type.TypeReference

instead of

import org.codehaus.jackson.type.TypeReference

like image 58
αƞjiβ Avatar answered Sep 07 '25 19:09

αƞjiβ


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

like image 41
akrita Avatar answered Sep 07 '25 19:09

akrita