Guest User

Untitled

a guest
Jul 20th, 2012
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. Jackson deserialization - with contained ArrayList<T>
  2. {"error":
  3. null,
  4. "object":
  5. "[{"Id":16,"Class":"ReportType","ClassID":"4","ListItemParent_ID":4,"Item":"Pothole","Description":"Pothole","Sequence":1,"LastEditDate":null,"LastEditor":null,"ItemStatus":"Active","ItemColor":"#00AF64"}
  6. ]"
  7. }
  8.  
  9. public class ListResponse {
  10.  
  11. public String error;
  12. public ArrayList<ListItem> object;
  13.  
  14. public ListResponse() {}
  15. }
  16.  
  17. public class ListItem {
  18. @JsonProperty("Id")
  19. public int id;
  20. @JsonProperty("Class")
  21. public String classType;
  22. @JsonProperty("ClassID")
  23. public String classId;
  24. @JsonProperty("ListItemParent_ID")
  25. public int parentId;
  26. @JsonProperty("Item")
  27. public String item;
  28. @JsonProperty("Description")
  29. public String description;
  30.  
  31. @JsonAnySetter
  32. public void handleUnknown(String key, Object value) {}
  33.  
  34. public ListItem() {}
  35. }
  36.  
  37. public class CitizenPlusService {
  38. private Client client = null;
  39. private WebResource service = null;
  40.  
  41. public CitizenPlusService() {
  42. initializeService("http://localhost:59105/PlusService/");
  43. }
  44.  
  45. private void initializeService(String baseURI) {
  46. // Use the default client configuration.
  47. ClientConfig clientConfig = new DefaultClientConfig();
  48. clientConfig.getClasses().add(JacksonJsonProvider.class);
  49.  
  50. client = Client.create(clientConfig);
  51.  
  52. // Add a logging filter to track communication between server and client.
  53. client.addFilter(new LoggingFilter());
  54. // Add the base URI
  55. service = client.resource(UriBuilder.fromUri(baseURI).build());
  56. }
  57.  
  58. public ListResponse getListItems(String id) throws Exception
  59. {
  60. ListResponse response = service.path("GetListItems").path(id).accept(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE).get(ListResponse.class);
  61. return response;
  62. }
  63.  
  64. org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token
  65. at [Source: java.io.StringReader@49497eb8; line: 1, column: 14] (through reference chain: citizenplus.types.ListResponse["object"])
Advertisement
Add Comment
Please, Sign In to add comment