use of org.codehaus.jackson.type.TypeReference in project crate by crate.
the class PingTaskTest method testSuccessfulPingTaskRun.
@Test
public void testSuccessfulPingTaskRun() throws Exception {
testServer = new HttpTestServer(18080, false);
testServer.run();
PingTask task = new PingTask(clusterService, clusterIdService, extendedNodeInfo, "http://localhost:18080/", Settings.EMPTY);
task.run();
assertThat(testServer.responses.size(), is(1));
task.run();
assertThat(testServer.responses.size(), is(2));
for (long i = 0; i < testServer.responses.size(); i++) {
String json = testServer.responses.get((int) i);
Map<String, String> map = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
try {
//convert JSON string to Map
map = mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
});
} catch (Exception e) {
e.printStackTrace();
}
assertThat(map, hasKey("kernel"));
assertThat(map.get("kernel"), is(notNullValue()));
assertThat(map, hasKey("cluster_id"));
assertThat(map.get("cluster_id"), is(notNullValue()));
assertThat(map, hasKey("master"));
assertThat(map.get("master"), is(notNullValue()));
assertThat(map, hasKey("ping_count"));
assertThat(map.get("ping_count"), is(notNullValue()));
Map<String, Long> pingCountMap;
pingCountMap = mapper.readValue(map.get("ping_count"), new TypeReference<Map<String, Long>>() {
});
assertThat(pingCountMap.get("success"), is(i));
assertThat(pingCountMap.get("failure"), is(0L));
if (task.getHardwareAddress() != null) {
assertThat(map, hasKey("hardware_address"));
assertThat(map.get("hardware_address"), is(notNullValue()));
}
assertThat(map, hasKey("crate_version"));
assertThat(map.get("crate_version"), is(notNullValue()));
assertThat(map, hasKey("java_version"));
assertThat(map.get("java_version"), is(notNullValue()));
}
}
use of org.codehaus.jackson.type.TypeReference in project Trello-Android by chrisHoekstra.
the class TrelloService method getNotifications.
public ArrayList<NotificationVO> getNotifications() {
ArrayList<NotificationVO> result = null;
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("key", PUBLIC_KEY));
params.add(new BasicNameValuePair("token", mToken));
HttpGet httpGet = new HttpGet(TRELLO_API_URL + "members/" + "me/" + "notifications?" + URLEncodedUtils.format(params, "UTF-8"));
HttpClient httpClient = getHttpClient();
try {
httpGet.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT_STRING);
HttpResponse response = httpClient.execute(httpGet, mContext);
if (response != null) {
result = mObjectMapper.readValue(mJsonFactory.createJsonParser(new InputStreamReader(response.getEntity().getContent(), "UTF-8")), new TypeReference<ArrayList<NotificationVO>>() {
});
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.
the class DiscussDao method mapperJson.
public DetailsOwnDiscussJson mapperJson(String url, boolean useCache) {
// TODO Auto-generated method stub
DetailsOwnDiscussJson json = null;
try {
String result = RequestCacheUtil.getRequestContent(mActivity, url, Constants.WebSourceType.Json, Constants.DBContentType.Discuss, useCache);
json = mObjectMapper.readValue(result, new TypeReference<DetailsOwnDiscussJson>() {
});
return json;
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.
the class WikiDao method getMore.
public WikiMoreResponse getMore(String more_url) {
WikiMoreResponse response;
try {
String result = RequestCacheUtil.getRequestContent(mActivity, more_url + Utility.getScreenParams(mActivity), Constants.WebSourceType.Json, Constants.DBContentType.Content_list, true);
response = mObjectMapper.readValue(result, new TypeReference<WikiMoreResponse>() {
});
return response;
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.
the class WikiDao method mapperJson.
public WikiResponseEntity mapperJson(boolean useCache) {
// TODO Auto-generated method stub
WikiJson wikiJson;
try {
String result = RequestCacheUtil.getRequestContent(mActivity, Urls.WIKI_LIST + Utility.getScreenParams(mActivity), Constants.WebSourceType.Json, Constants.DBContentType.Content_list, useCache);
wikiJson = mObjectMapper.readValue(result, new TypeReference<WikiJson>() {
});
if (wikiJson == null) {
return null;
}
this.mWikiResponseEntity = wikiJson.getResponse();
return mWikiResponseEntity;
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations