Package com.google.gson

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


        flat.put("type", "chat");
        flat.put("title", title);
        flat.put("body", body);
        flat.put("dialogue", dialogue);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = (ChatPost) gson.fromJson(flatSerialize(flat), Post.class);
    }

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


    public void setup() {
        Map<String, Object> flat = new HashMap<String, Object>();
        flat.put("type", "nonexistent");
        flat.put("id", id);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = gson.fromJson(flatSerialize(flat), Post.class);
    }

    @Test
    public void isFound() {
        UnknownTypePost upost = (UnknownTypePost) post;
View Full Code Here

        flat.put("ask", ask);
        flat.put("ask_anon", ask_anon);
        flat.put("followers", followers);

        Gson gson = new Gson();
        blog = gson.fromJson(flatSerialize(flat), Blog.class);
        blog.setName(blog.getName());
        client = mock(JumblrClient.class);
        blog.setClient(client);
    }
View Full Code Here

        flat.put("author", author);
        flat.put("slug", slug);
        flat.put("notes", notes);
        flat.put("note_count", 123);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = (QuotePost) gson.fromJson(flatSerialize(flat), Post.class);
    }

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

        flat.put("likes", likes);
        flat.put("blogs", blogs);
        flat.put("default_post_format", default_post_format);

        Gson gson = new Gson();
        user = gson.fromJson(flatSerialize(flat), User.class);
    }

    @Test
    public void testReaders() {
        assertEquals(default_post_format, user.getDefaultPostFormat());
View Full Code Here

        flat.put("caption", caption);
        flat.put("width", width);
        flat.put("height", height);
        flat.put("photos", photos);
        Gson gson = new GsonBuilder().registerTypeAdapter(Post.class, new PostDeserializer()).create();
        post = (PhotoPost) gson.fromJson(flatSerialize(flat), Post.class);
    }

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

  protected String text(String entity, Type type) {
    switch (type) {
    case JSON:
      Gson gson = new Gson();
      return gson.fromJson(entity, Page.class).content;
    case XML:
      XStream xstream = new XStream();
      xstream.alias("page", Page.class);
      xstream.ignoreUnknownElements();
      return ((Page) xstream.fromXML(entity)).content;
View Full Code Here

    return format(INDEX_URI, rootPath);
  }

  private Collection<Page> parse(String entity) {
    Gson gson = new Gson();
    return gson.<Collection<Page>> fromJson(
        jsonMember(entity, "pageSummaries"),
        new TypeToken<Collection<Page>>() {
        }.getType());
  }
View Full Code Here

    return format(INDEX_URI, rootPath);
  }

    private Collection<Page> parse(String entity) {
        Gson gson = new Gson();
        return gson.<Collection<Page>> fromJson(jsonMember(entity, "wiki_pages"),
                new TypeToken<Collection<Page>>() {
                }.getType());
    }

    private String jsonMember(String entity, String memberName) {
View Full Code Here

  protected String text(String entity, Type type) {
    switch (type) {
    case JSON:
      Gson gson = new Gson();
      return gson.fromJson(jsonMember(entity, "wiki_page"),
          WikiPage.class).text;
    case XML:
      XStream xstream = new XStream();
      xstream.alias("wiki_page", WikiPage.class);
      xstream.ignoreUnknownElements();
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.