예제 #1
0
  @org.junit.Test
  public void toJson() throws Exception {
    JsonObject json =
        GsonProto.toJson(
            Test.A
                .newBuilder()
                .setA(Test.B.newBuilder().setA(1))
                .setB(true)
                .setC(1)
                .setD(1)
                .setE(1)
                .setF(1)
                .setG(1)
                .setH(1)
                .setI(1)
                .setJ(1)
                .setK(1)
                .setL(1)
                .setM("one"));

    assertEquals(1, json.get("a").getAsJsonObject().get("a").getAsInt());
    assertEquals(true, json.get("b").getAsBoolean());
    assertEquals(1, json.get("c").getAsInt());
    assertEquals(1, json.get("d").getAsInt());
    assertEquals(1, json.get("e").getAsInt());
    assertEquals(1, json.get("f").getAsInt());
    assertEquals(1, json.get("g").getAsInt());
    assertEquals(1, json.get("h").getAsLong());
    assertEquals(1, json.get("i").getAsLong());
    assertEquals(1, json.get("j").getAsLong());
    assertEquals(1, json.get("k").getAsLong());
    assertEquals(1, json.get("l").getAsLong());
    assertEquals("one", json.get("m").getAsString());
  }