Package com.google.gson

Examples of com.google.gson.Gson.fromJson()


    protected XingUser fetchUser(final Token accessToken) throws Exception {
        final OAuthRequest request = new OAuthRequest(Verb.GET, usersMeUrl);
        oAuthService.signRequest(accessToken, request);
        final Response response = request.send();
        final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        final Users users = gson.fromJson(response.getBody(), Users.class);
        return users.getUsers().get(0);
    }

    protected void removeAuthFromSession(final HttpServletRequest request) {
        try {
View Full Code Here


        return null;
    }

    public static XingUser fromJson(final String json) {
        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>();
View Full Code Here

    }

    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

    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

    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

    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

            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

        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

        flat.put("player", videos);
        flat.put("thumbnail_url", thumbnailUrl);
        flat.put("thumbnail_width", thumbnailWidth);
        flat.put("thumbnail_height", thumbnailHeight);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = (VideoPost) gson.fromJson(flatSerialize(flat), Post.class);
    }

    @Test
    public void testReaders() {
        assertEquals(caption, post.getCaption());
View Full Code Here

            String json = response.getBody();
            try {
                Gson gson = new GsonBuilder().
                        registerTypeAdapter(JsonElement.class, new JsonElementDeserializer()).
                        create();
                ResponseWrapper wrapper = gson.fromJson(json, ResponseWrapper.class);
                if (wrapper == null) {
                    throw new JumblrException(response);
                }
                wrapper.setClient(client);
                return wrapper;
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.