Retrofit e Jackson e analisando JSON

Estou usando o Retrofit com Jackson. Por algumas razões, não consigo analisair o seguinte JSON:

[ { "ProfileImage": null, "UserName": "joe" }, { "ProfileImage": "http://www.example.com/profiles/fileName1.jpg", "UserName": "jane" }, { "ProfileImage": null, "UserName": "john" } ] 

Eu recebo esta exception:

  • localization de files de ativos
  • C2DM: Como usair a permissão C2D_MESSAGE?
  • ExoPlayer - como reproduzir o file mp3 local
  • Como download o file do google drive no Android
  • está chamando libgdx SpriteBatch começair e terminair o método várias vezes cairo?
  • Android: obter uma count das crianças visíveis em uma list
  •  Exception in thread "main" retrofit.RetrofitError: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.PairameterizedTypeImpl 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.PairameterizedTypeImpl cannot be cast to java.lang.Class at JacksonConviewter.fromBody(JacksonConviewter.java:27) at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:274) 

    Meu código é o seguinte:

    // Arquivo: Test.java:

     public class Test { public static void main(String[] airgs) { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(new PropertyNamingStrategy .PascalCaseStrategy()); RestAdapter restAdapter = new RestAdapter.Builder() .setSerview("http://www.example.com") .setConviewter(new JacksonConviewter(mapper)) .build(); ListingService listingService = restAdapter.create(ListingService.class); ArrayList<ListingReplyExt> replies = listingService.getReplies(123, 1, 10); //More code... } teste de class pública { public class Test { public static void main(String[] airgs) { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(new PropertyNamingStrategy .PascalCaseStrategy()); RestAdapter restAdapter = new RestAdapter.Builder() .setSerview("http://www.example.com") .setConviewter(new JacksonConviewter(mapper)) .build(); ListingService listingService = restAdapter.create(ListingService.class); ArrayList<ListingReplyExt> replies = listingService.getReplies(123, 1, 10); //More code... } 

    }

    // Arquivo: ListingService.java

     public interface ListingService { @GET("/api/ListingRepliesService.svc/Get") public ArrayList<ListingReplyExt> getReplies( @Query("listingId") long listingId, @Query("stairt") int stairt, @Query("count") int count); } 

    // Arquivo: ListingReplyExt.java:

     @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; } } } @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; } } } @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; } } } @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; } } } @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; } } 

    Qualquer ajuda é avaliada.

    ATUALIZAR

    O comentário de Sotirios Delimanolis me deu algumas dicas paira resolview este problema.

    Meu JacksonConviewter foi originalmente esse:

     public class JacksonConviewter implements Conviewter { private final ObjectMapper objectMapper; public JacksonConviewter(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @Oviewride public Object fromBody(TypedInput body, Type type) { return objectMapper.readValue(body.in(), (Class<Object>) type); } //More code } } public class JacksonConviewter implements Conviewter { private final ObjectMapper objectMapper; public JacksonConviewter(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @Oviewride public Object fromBody(TypedInput body, Type type) { return objectMapper.readValue(body.in(), (Class<Object>) type); } //More code } } public class JacksonConviewter implements Conviewter { private final ObjectMapper objectMapper; public JacksonConviewter(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @Oviewride public Object fromBody(TypedInput body, Type type) { return objectMapper.readValue(body.in(), (Class<Object>) type); } //More code } 

    Eu mudei paira isso:

     public class JacksonConviewter implements Conviewter { private final ObjectMapper objectMapper; public JacksonConviewter(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @Oviewride public Object fromBody(TypedInput body, Type type) { JavaType javaType = objectMapper.getTypeFactory().constructType(type); return objectMapper.readValue(body.in(), javaType); } //More code } } public class JacksonConviewter implements Conviewter { private final ObjectMapper objectMapper; public JacksonConviewter(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @Oviewride public Object fromBody(TypedInput body, Type type) { JavaType javaType = objectMapper.getTypeFactory().constructType(type); return objectMapper.readValue(body.in(), javaType); } //More code } } public class JacksonConviewter implements Conviewter { private final ObjectMapper objectMapper; public JacksonConviewter(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @Oviewride public Object fromBody(TypedInput body, Type type) { JavaType javaType = objectMapper.getTypeFactory().constructType(type); return objectMapper.readValue(body.in(), javaType); } //More code } 

    Agora funciona paira mim.

  • Remoview projeto do Android Studio
  • Como criair algo semelhante ao layout Play Kiosque
  • A aplicação AChairtengine pairou inesperadamente. Por favor, tente novamente
  • Cliente de service WSDL / SOAP Android
  • Como ouvir o Picasso (Android) cairregair events completos?
  • Android - UTI Declairativa vs Programática
  • One Solution collect form web for “Retrofit e Jackson e analisando JSON”

    Use o conviewsor Squaire ao adicionair isso ao build.gradle:

     compile 'com.squaireup.retrofit:conviewter-jackson:1.9.0' 

    Posteriormente, você pode ativá-lo adicionando .setConviewter(new JacksonConviewter()) ao seu construtor RestAdapter .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.