Package com.google.gson

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


    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<Post> getPosts() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        List<Post> l = gson.fromJson(object.get("posts"), new TypeToken<List<Post>>() {}.getType());
        for (Post e : l) { e.setClient(client); }
        return l;
    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
View Full Code Here


    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<User> getUsers() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        List<User> l = gson.fromJson(object.get("users"), new TypeToken<List<User>>() {}.getType());
        for (User e : l) { e.setClient(client); }
        return l;
    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
View Full Code Here

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<Post> getLikedPosts() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        List<Post> l = gson.fromJson(object.get("liked_posts"), new TypeToken<List<Post>>() {}.getType());
        for (Post e : l) { e.setClient(client); }
        return l;
    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
View Full Code Here

    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<Post> getTaggedPosts() {
        Gson gson = gsonParser();
        List<Post> l = gson.fromJson(response.getAsJsonArray(), new TypeToken<List<Post>>() {}.getType());
        for (Post e : l) { e.setClient(client); }
        return l;
    }

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
View Full Code Here

    // NOTE: needs to be duplicated logic due to Java erasure of generic types
    public List<Blog> getBlogs() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        List<Blog> l = gson.fromJson(object.get("blogs"), new TypeToken<List<Blog>>() {}.getType());
        for (Blog e : l) { e.setClient(client); }
        return l;
    }

    /**
 
View Full Code Here

     **/

    private <T extends Resource> T get(String field, Class<T> k) {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;
        T e = gson.fromJson(object.get(field).toString(), k);
        e.setClient(client);
        return e;
    }

    private Gson gsonParser() {
View Full Code Here

        flat.put("type", "link");
        flat.put("title", title);
        flat.put("description", desc);
        flat.put("url", url);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = (LinkPost) gson.fromJson(flatSerialize(flat), Post.class);
    }

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

        flat.put("album_art", albumArtUrl);
        flat.put("year", year);
        flat.put("track_number", trackNumber);
        flat.put("player", embedCode);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = (AudioPost) gson.fromJson(flatSerialize(flat), Post.class);
    }

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

        flat.put("body", body);
        flat.put("note_count", noteCount);
        flat.put("reblogged_from_id", rebloggedFromId);
        flat.put("reblogged_from_name", rebloggedFromName);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = (TextPost) gson.fromJson(flatSerialize(flat), Post.class);
    }

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

        flat.put("asking_url", askingUrl);
        flat.put("asking_name", askingName);
        flat.put("question", question);
        flat.put("answer", answer);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = (AnswerPost) gson.fromJson(flatSerialize(flat), Post.class);
    }

    @Test
    public void getAskingName() {
        assertEquals(askingName, post.getAskingName());
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.