Search in sources :

Example 6 with JsonParseException

use of org.codehaus.jackson.JsonParseException 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)

Example 7 with JsonParseException

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

the class BlogsDao method getMore.

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

Example 8 with JsonParseException

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

the class DetailDao method mapperJson.

public DetailResponseEntity mapperJson(boolean useCache) {
    try {
        String result = RequestCacheUtil.getRequestContent(mActivity, mUrl, Constants.WebSourceType.Json, Constants.DBContentType.Content_content, useCache);
        Log.i("info", mUrl);
        DetailJson detailJson = mObjectMapper.readValue(result, new TypeReference<DetailJson>() {
        });
        this.mDetailResponseEntity = detailJson.getResponse();
        return this.mDetailResponseEntity;
    } 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 : DetailJson(cn.eoe.app.entity.DetailJson) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) 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 9 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project databus by linkedin.

the class TestDbusEventBufferMult method convertToPhysicalSourceConfig.

public PhysicalSourceConfig convertToPhysicalSourceConfig(String str) {
    _mapper = new ObjectMapper();
    InputStreamReader isr = new InputStreamReader(IOUtils.toInputStream(str));
    PhysicalSourceConfig pConfig = null;
    try {
        pConfig = _mapper.readValue(isr, PhysicalSourceConfig.class);
    } catch (JsonParseException e) {
        fail("Failed parsing", e);
    } catch (JsonMappingException e) {
        fail("Failed parsing", e);
    } catch (IOException e) {
        fail("Failed parsing", e);
    }
    try {
        isr.close();
    } catch (IOException e) {
        fail("Failed", e);
    }
    return pConfig;
}
Also used : PhysicalSourceConfig(com.linkedin.databus2.relay.config.PhysicalSourceConfig) InputStreamReader(java.io.InputStreamReader) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 10 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project openhab1-addons by openhab.

the class OpenPathsBinding method getUserLocation.

@SuppressWarnings("unchecked")
private Location getUserLocation(String accessKey, String secretKey) {
    // build the OAuth service using the access/secret keys
    OAuthService service = new ServiceBuilder().provider(new OpenPathsApi()).apiKey(accessKey).apiSecret(secretKey).build();
    // build the request
    OAuthRequest request = new OAuthRequest(Verb.GET, "https://openpaths.cc/api/1");
    service.signRequest(Token.empty(), request);
    request.addQuerystringParameter("num_points", "1");
    // send the request and check we got a successful response
    Response response = request.send();
    if (!response.isSuccessful()) {
        logger.error("Failed to request the OpenPaths location, response code: " + response.getCode());
        return null;
    }
    // parse the response to build our location object
    Map<String, Object> locationData;
    String toParse = "{}";
    try {
        ObjectMapper jsonReader = new ObjectMapper();
        toParse = response.getBody();
        toParse = toParse.substring(1, toParse.length() - 2);
        locationData = jsonReader.readValue(toParse, Map.class);
    } catch (JsonParseException e) {
        logger.error("Error parsing JSON:\n" + toParse, e);
        return null;
    } catch (JsonMappingException e) {
        logger.error("Error mapping JSON:\n" + toParse, e);
        return null;
    } catch (IOException e) {
        logger.error("An I/O error occured while decoding JSON:\n" + response.getBody());
        return null;
    }
    float latitude = Float.parseFloat(locationData.get("lat").toString());
    float longitude = Float.parseFloat(locationData.get("lon").toString());
    String device = locationData.get("device").toString();
    return new Location(latitude, longitude, device);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ServiceBuilder(org.scribe.builder.ServiceBuilder) Response(org.scribe.model.Response) OAuthService(org.scribe.oauth.OAuthService) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

JsonParseException (org.codehaus.jackson.JsonParseException)38 IOException (java.io.IOException)33 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)33 TypeReference (org.codehaus.jackson.type.TypeReference)9 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 HashMap (java.util.HashMap)3 BlogsMoreResponse (cn.eoe.app.entity.BlogsMoreResponse)2 NewsMoreResponse (cn.eoe.app.entity.NewsMoreResponse)2 WikiMoreResponse (cn.eoe.app.entity.WikiMoreResponse)2 ByteString (com.linkedin.data.ByteString)2 PhysicalSourceConfig (com.linkedin.databus2.relay.config.PhysicalSourceConfig)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 MessagingException (javax.mail.MessagingException)2