Десериализация Джексона - с содержащимся ArrayList <T>
Добрый день,
В настоящее время я пытаюсь использовать службу REST, которая создает JSON (написанный на .NET), используя Джексона (с Джерси). JSON состоит из сообщения о возможной ошибке и массива объектов. Ниже приведен пример JSON-файла, возвращенного фильтром журналирования Джерси:
{
"error":null,
"object":"[{\"Id\":16,\"Class\":\"ReportType\",\"ClassID\":\"4\",\"ListItemParent_ID\":4,\"Item\":\"Pothole\",\"Description\":\"Pothole\",\"Sequence\":1,\"LastEditDate\":null,\"LastEditor\":null,\"ItemStatus\":\"Active\",\"ItemColor\":\"#00AF64\"}]"
}
У меня есть два класса для представления типа (внешний ListResponse):
public class ListResponse {
public String error;
public ArrayList<ListItem> object;
public ListResponse() {
}
}
и (внутренний ListItem):
public class ListItem {
@JsonProperty("Id")
public int id;
@JsonProperty("Class")
public String classType;
@JsonProperty("ClassID")
public String classId;
@JsonProperty("ListItemParent_ID")
public int parentId;
@JsonProperty("Item")
public String item;
@JsonProperty("Description")
public String description;
@JsonAnySetter
public void handleUnknown(String key, Object value) {}
public ListItem() {
}
}
Класс, который вызывает и возвращает JSON, выглядит следующим образом:
public class CitizenPlusService {
private Client client = null;
private WebResource service = null;
public CitizenPlusService() {
initializeService("http://localhost:59105/PlusService/");
}
private void initializeService(String baseURI) {
// Use the default client configuration.
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getClasses().add(JacksonJsonProvider.class);
client = Client.create(clientConfig);
// Add a logging filter to track communication between server and client.
client.addFilter(new LoggingFilter());
// Add the base URI
service = client.resource(UriBuilder.fromUri(baseURI).build());
}
public ListResponse getListItems(String id) throws Exception
{
ListResponse response = service.path("GetListItems").path(id).accept(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE).get(ListResponse.class);
return response;
}
}
Важным вызовом здесь является метод getListItems. Запустив код в тестовом жгуте, выдает следующее:
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token
at [Source: java.io.StringReader@49497eb8; line: 1, column: 14] (through reference chain: citizenplus.types.ListResponse["object"])
Пожалуйста помогите.
С Уважением, Карл-Питер Мейер