Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.
mstssk edited this page Mar 19, 2014 · 11 revisions

JsonPullParser

日本語は下の方にあります。 (For Japanese, look page bottom.)


Good JSON-POJO Mapper for your Java-code.

Create POJO

@JsonModel
public class Entity {
  @JsonKey
  String foo;

  @JsonKey
  int bar;

  public String getFoo() {
    return foo;
  }

  public void setFoo(String foo) {
    this.foo = foo;
  }

  public int getBar() {
    return bar;
  }

  public void setBar(int bar) {
    this.bar = bar;
  }
}

Auto generate a mapper class from the Annotations. You can easily use.

public class EntityTest {
  @Test
  public void jsonToPojo() throws IOException, JsonFormatException {
    Entity entity = EntityGen.get("{\\"foo\":\\"1st\\",\\"bar\\":2}");

    assertThat(entity.getFoo(), is("1st"));
    assertThat(entity.getBar(), is(2));
  }

  @Test
  public void pojoToJson() throws IOException, JsonFormatException {
    Entity entity = new Entity();
    entity.setFoo("3rd");
    entity.setBar(4);

    Writer writer = new StringWriter();
    EntityGen.encode(writer, entity);

    assertThat(writer.toString(), is("{\\"foo\\":\\"3rd\\",\\"bar\\":4}"));
  }
}

Please check usage project or Android sample .

Articles

Support

Discussion and QA: Google Group – en
Discussion and QA: Google Group – ja
Report bugs at GitHub (In English or Japanese)
Twitter: @vvakame (In English or Japanese)


For japanese.