Search in sources :

Example 16 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project crate by crate.

the class PingTaskTest method testUnsuccessfulPingTaskRun.

@Test
public void testUnsuccessfulPingTaskRun() throws Exception {
    testServer = new HttpTestServer(18081, true);
    testServer.run();
    PingTask task = new PingTask(clusterService, clusterIdService, extendedNodeInfo, "http://localhost:18081/", 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(0L));
        assertThat(pingCountMap.get("failure"), is(i));
        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 17 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.

the class NewsDao method getMore.

public NewsMoreResponse getMore(String more_url) {
    NewsMoreResponse 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<NewsMoreResponse>() {
        });
        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) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) NewsMoreResponse(cn.eoe.app.entity.NewsMoreResponse) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 18 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.

the class NewsDao method mapperJson.

public NewsResponseEntity mapperJson(boolean useCache) {
    // TODO Auto-generated method stub
    NewsJson newsJson;
    try {
        String result = RequestCacheUtil.getRequestContent(mActivity, Urls.NEWS_LIST + Utility.getScreenParams(mActivity), Constants.WebSourceType.Json, Constants.DBContentType.Content_list, useCache);
        newsJson = mObjectMapper.readValue(result, new TypeReference<NewsJson>() {
        });
        if (newsJson == null) {
            return null;
        }
        this._newsResponse = newsJson.getResponse();
        return _newsResponse;
    } 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 : NewsJson(cn.eoe.app.entity.NewsJson) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonParseException(org.codehaus.jackson.JsonParseException) IOException(java.io.IOException)

Example 19 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.

the class SearchDao method mapperJson.

/**
	 * 这里的逻辑判断得优化 目前仅为实现功能编写的代码 不妥
	 * 
	 * @return
	 */
public List<Object> mapperJson() {
    categorys.clear();
    tabs.clear();
    hasChild = false;
    try {
        if (mTag.equals("news")) {
            NewsSearchJson newsSearchJson = mObjectMapper.readValue(HttpUtils.getByHttpClient(mActivity, Urls.BASE_SEARCH_URL + "t=" + mTag + "&w=" + keyWord + Utility.getScreenParams(mActivity)), new TypeReference<NewsSearchJson>() {
            });
            categorys.add(newsSearchJson.getResponse());
            cate_name = newsSearchJson.getResponse().getName();
            if (newsSearchJson.getResponse().getItems() != null) {
                hasChild = true;
            }
        } else if (mTag.equals("wiki")) {
            WikiSearchJson wikiSearchJson = mObjectMapper.readValue(HttpUtils.getByHttpClient(mActivity, Urls.BASE_SEARCH_URL + "t=" + mTag + "&w=" + keyWord), new TypeReference<WikiSearchJson>() {
            });
            categorys.add(wikiSearchJson.getResponse());
            cate_name = wikiSearchJson.getResponse().getName();
            if (wikiSearchJson.getResponse().getItems() != null) {
                hasChild = true;
            }
        } else if (mTag.equals("blog")) {
            BlogSearchJson blogSearchJson = mObjectMapper.readValue(HttpUtils.getByHttpClient(mActivity, Urls.BASE_SEARCH_URL + "t=" + mTag + "&w=" + keyWord), new TypeReference<BlogSearchJson>() {
            });
            categorys.add(blogSearchJson.getResponse());
            cate_name = blogSearchJson.getResponse().getName();
            if (blogSearchJson.getResponse().getItems() != null) {
                hasChild = true;
            }
        }
        return categorys;
    } 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 : BlogSearchJson(cn.eoe.app.entity.BlogSearchJson) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) NewsSearchJson(cn.eoe.app.entity.NewsSearchJson) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) IOException(java.io.IOException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonParseException(org.codehaus.jackson.JsonParseException) WikiSearchJson(cn.eoe.app.entity.WikiSearchJson)

Example 20 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.

the class UserDao method mapperJson.

public UserResponse mapperJson(String key) {
    // TODO Auto-generated method stub
    UserJson userJson;
    try {
        if (!key.contains(":")) {
            return null;
        }
        String url = String.format(Urls.KEYBindURL, key) + Utility.getParams(key);
        String result = HttpUtils.getByHttpClient(mContext, url);
        userJson = mObjectMapper.readValue(result, new TypeReference<UserJson>() {
        });
        if (userJson == null) {
            return null;
        }
        return userJson.getResponse();
    } 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 : UserJson(cn.eoe.app.entity.UserJson) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) 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