Search code examples
jsonjackson

readValue() no working with TypeReference


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?


Solution

  • Issue was with import of TypeReference. I was using

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

    instead of

    import org.codehaus.jackson.type.TypeReference