Search in sources :

Example 1 with TypeReference

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()));
    }
}
Also used : HashMap(java.util.HashMap) HttpTestServer(io.crate.http.HttpTestServer) TypeReference(org.codehaus.jackson.type.TypeReference) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with TypeReference

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) NotificationVO(com.chrishoekstra.trello.vo.NotificationVO) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 3 with TypeReference

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;
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) DetailsOwnDiscussJson(cn.eoe.app.entity.DetailsOwnDiscussJson)

Example 4 with TypeReference

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;
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) WikiMoreResponse(cn.eoe.app.entity.WikiMoreResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 5 with TypeReference

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;
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) WikiJson(cn.eoe.app.entity.WikiJson) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonParseException(org.codehaus.jackson.JsonParseException) IOException(java.io.IOException)

Aggregations

TypeReference (org.codehaus.jackson.type.TypeReference)28 IOException (java.io.IOException)16 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)10 JsonParseException (org.codehaus.jackson.JsonParseException)9 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 InputStreamReader (java.io.InputStreamReader)4 HashMap (java.util.HashMap)4 HttpResponse (org.apache.http.HttpResponse)4 ClientProtocolException (org.apache.http.client.ClientProtocolException)4 HttpClient (org.apache.http.client.HttpClient)4 HttpGet (org.apache.http.client.methods.HttpGet)3 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 File (java.io.File)2 List (java.util.List)2 Test (org.junit.Test)2 Activate (aQute.bnd.annotation.component.Activate)1 BlogSearchJson (cn.eoe.app.entity.BlogSearchJson)1