Examples of Gson


Examples of com.google.gson.Gson

        final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        return gson.fromJson(json, XingUser.class);
    }

    public static String hash(final String json, final String secretKey, final String hashAlgorithm) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
        final Gson gson = new Gson();
        final List<String> list = new ArrayList<String>();
        final Map map = gson.fromJson(json, Map.class);
        join(map, list, "");
        Collections.sort(list);
        final String message = StringUtils.join(list, null);
        final byte[] result = hmac(message, secretKey, hashAlgorithm);
        return Hex.encodeHexString(result);
View Full Code Here

Examples of com.google.gson.Gson

public class SubscriptionUtil {
 
  private static final String HMAC_SHA1 = "HmacSHA1";
   
    public static SubscriptionResponseObject[] getSubscriptionResponseData(String jsonBody) throws InstagramException {
        Gson gson = new Gson();
        SubscriptionResponseObject[] responseData;

          try {
            responseData = gson.fromJson(jsonBody, SubscriptionResponseObject[].class);
          } catch (Exception e) {
              throw new InstagramException("Error parsing json to object type ");
          }

          return responseData;
View Full Code Here

Examples of com.google.gson.Gson

        return request;
    }

    private SubscriptionResponse getSubscriptionResponse(String jsonBody) throws InstagramException {
        Gson gson = new Gson();
        SubscriptionResponse response;

        try {
            response = gson.fromJson(jsonBody, SubscriptionResponse.class);
        } catch (Exception e) {
            throw new InstagramException("Error parsing json to object type ");
        }

        return response;
View Full Code Here

Examples of com.google.gson.Gson

        return response;
    }

    private SubscriptionsListResponse getSubscriptionsListResponse(String jsonBody) throws InstagramException {
        Gson gson = new Gson();
        SubscriptionsListResponse response = null;

        try {
            response = gson.fromJson(jsonBody, SubscriptionsListResponse.class);
        } catch (Exception e) {
            throw new InstagramException("Error parsing json to object type ");
        }

        return response;
View Full Code Here

Examples of com.google.gson.Gson

            throw handleInstagramError(response);
        }

    protected InstagramException handleInstagramError(Response response) throws InstagramException {
        Gson gson = new Gson();
        final InstagramErrorResponse error;
        try {
            if (response.getCode() == 400) {
                error = InstagramErrorResponse.parse(gson, response.getBody());
                error.setHeaders(response.getHeaders());
View Full Code Here

Examples of com.google.gson.Gson

   * @param response a JSON feed
   * @return a object of type <T>
   * @throws InstagramException if any error occurs.
   */
        protected <T> T createObjectFromResponse(Class<T> clazz, final String response) throws InstagramException {
            Gson gson = new Gson();
            T object;

            try {
                object = clazz.newInstance();
      object = gson.fromJson(response, clazz);
    }
    catch (InstantiationException e) {
      throw new InstagramException("Problem in Instantiation of type " + clazz.getName(), e);
    }
    catch (IllegalAccessException e) {
View Full Code Here

Examples of com.google.gson.Gson

        throw handleInstagramError(response);
    }

    private InstagramException handleInstagramError(Response response) throws InstagramException {
        if (response.getCode() == 400) {
            Gson gson = new Gson();
            final InstagramErrorResponse error = InstagramErrorResponse.parse(gson, response.getBody());
            error.setHeaders(response.getHeaders());
            error.throwException();
        }
        throw new InstagramException("Unknown error response code: " + response.getCode() + " " + response.getBody(), response.getHeaders());
View Full Code Here

Examples of com.google.gson.Gson

     * @param response a JSON feed
     * @return a object of type <T>
     * @throws InstagramException if any error occurs.
     */
    private <T> T createObjectFromResponse(Class<T> clazz, final String response) throws InstagramException {
        Gson gson = new Gson();
        T object = null;

        try {
            object = clazz.newInstance();
            object = gson.fromJson(response, clazz);
        }
        catch (InstantiationException e) {
            throw new InstagramException("Problem in Instantiation of type " + clazz.getName(), e);
        }
        catch (IllegalAccessException e) {
View Full Code Here

Examples of com.google.gson.Gson

      JSONEvent e = new JSONEvent();
      e.setHeaders(input);
      e.setBody(String.valueOf(rand.nextGaussian()).getBytes(encoding));
      events.add(e);
    }
    Gson gson = new Gson();
    String json = gson.toJson(events, listType);
    StringEntity input = new StringEntity(json);
    input.setContentType("application/json; charset=" + encoding);
    postRequest.setEntity(input);
    HttpResponse resp = httpClient.execute(postRequest);
    return new ResultWrapper(resp, events);
View Full Code Here

Examples of com.google.gson.Gson

      JSONEvent e = new JSONEvent();
      e.setHeaders(input);
      e.setBody(String.valueOf(rand.nextGaussian()).getBytes("UTF-8"));
      events.add(e);
    }
    Gson gson = new Gson();
    String json = gson.toJson(events, listType);
    HttpsURLConnection httpsURLConnection = null;
    try {
      TrustManager[] trustAllCerts = {new X509TrustManager() {
        @Override
        public void checkClientTrusted(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.