title: Retrofit and Jackson and parsing JSON
body: <p>I am using Retrofit with Jackson. For some reasons I cannot parse the following JSON:</p>
  
  <pre><code>[
      {
          "ProfileImage": null,
          "UserName": "joe"
      },
      {
          "ProfileImage": "http://www.example.com/profiles/fileName1.jpg",
          "UserName": "jane"
      },
      {
          "ProfileImage": null,
          "UserName": "john"
      }
  ]
  </code></pre>
  
  <p>I get the this exception:</p>
  
  <pre><code>Exception in thread "main" retrofit.RetrofitError: java.lang.ClassCastException: 
      sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl 
      cannot be cast to java.lang.Class
  
  at retrofit.RetrofitError.unexpectedError(RetrofitError.java:41)
  at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:294)
  at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:182)
  at com.sun.proxy.$Proxy5.getReplies(Unknown Source)
  at Test.main(Test.java:25)
  
  Caused by: java.lang.ClassCastException: 
      sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl 
      cannot be cast to java.lang.Class
  
  at JacksonConverter.fromBody(JacksonConverter.java:27)
  at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:274)
  </code></pre>
  
  <p>My code is as follow:</p>
  
  <p>//File: Test.java:</p>
  
  <pre><code>public class Test { 
      public static void main(String[] args) {
  
          ObjectMapper mapper = new ObjectMapper();
          mapper.setPropertyNamingStrategy(new PropertyNamingStrategy
                                                   .PascalCaseStrategy());
  
          RestAdapter restAdapter = new RestAdapter.Builder()
                                        .setServer("http://www.example.com")
                                        .setConverter(new JacksonConverter(mapper))
                                        .build();
  
          ListingService listingService = restAdapter.create(ListingService.class);
          ArrayList&lt;ListingReplyExt&gt; replies = listingService.getReplies(123, 1, 10);
          //More code...
  }
  </code></pre>
  
  <p>}</p>
  
  <p>//File: ListingService.java</p>
  
  <pre><code>public interface ListingService {       
      @GET("/api/ListingRepliesService.svc/Get")
      public ArrayList&lt;ListingReplyExt&gt; getReplies(
                                             @Query("listingId") long listingId,
                                             @Query("start") int start,
                                             @Query("count") int count);
  }
  </code></pre>
  
  <p>//File: ListingReplyExt.java:</p>
  
  <pre><code>@JsonIgnoreProperties(ignoreUnknown = true)
  public class ListingReplyExt {
  
      private String profileImage;
      private String username;
  
      @JsonProperty(value = "ProfileImage")
      public String getProfileImage() {
          return profileImage;
      }
  
      @JsonProperty(value = "ProfileImage")
      public void setProfileImage(String profileImage) {
          this.profileImage = profileImage;
      }
  
      @JsonProperty(value = "UserName")
      public String getUsername() {
          return username;
      }
  
      @JsonProperty(value = "UserName")
      public void setUsername(String username) {
          this.username = username;
      }
  }
  </code></pre>
  
  <p>Any help is appriciated.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Sotirios Delimanolis' comment gave me some hints to resolve this issue.</p>
  
  <p>My JacksonConverter was originally this:</p>
  
  <pre><code>public class JacksonConverter implements Converter {
      private final ObjectMapper objectMapper;
  
      public JacksonConverter(ObjectMapper objectMapper) {
          this.objectMapper = objectMapper;
      }
  
      @Override public Object fromBody(TypedInput body, Type type) {
          return objectMapper.readValue(body.in(), (Class&lt;Object&gt;) type);
      }
  
      //More code
  }
  </code></pre>
  
  <p>I changed it to this:</p>
  
  <pre><code>public class JacksonConverter implements Converter {
      private final ObjectMapper objectMapper;
  
      public JacksonConverter(ObjectMapper objectMapper) {
          this.objectMapper = objectMapper;
      }
  
      @Override public Object fromBody(TypedInput body, Type type) {
          JavaType javaType = objectMapper.getTypeFactory().constructType(type);
          return objectMapper.readValue(body.in(), javaType);
      }
  
      //More code
  }
  </code></pre>
  
  <p>Now it works for me.</p>