public void testJsonList() throws IOException {
JsonHandler jsonHandler = new JsonHandler();
jsonHandler.setMapper(new ObjectMapper());
List<ExtDirectRequest> requests = new ArrayList<ExtDirectRequest>();
ExtDirectRequest req = new ExtDirectRequest();
req.setAction("testAction1");
req.setMethod("testMethod1");
req.setTid(1);
req.setType("testType1");
req.setData(new Object[] { "one" });
requests.add(req);
req = new ExtDirectRequest();
req.setAction("testAction2");
req.setMethod("testMethod2");
req.setTid(2);
req.setType("testType2");
req.setData(new Object[] { "two" });
requests.add(req);
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(requests);
List<ExtDirectRequest> desRequests = jsonHandler.readValue(json,
new TypeReference<List<ExtDirectRequest>>() {/* empty */
});
assertEquals(requests.size(), desRequests.size());
for (int i = 0; i < requests.size(); i++) {
req = requests.get(i);
ExtDirectRequest desReq = desRequests.get(i);
assertEquals(req.getAction(), desReq.getAction());
assertArrayEquals((Object[]) req.getData(),
((List<Object>) desReq.getData()).toArray());
assertEquals(req.getMethod(), desReq.getMethod());
assertEquals(req.getTid(), desReq.getTid());
assertEquals(req.getType(), desReq.getType());
}
}