Esempio n. 1
0
 @Test
 public void test3() {
   String jsonStr =
       "{\"id\":33442,\"date\":null,\"add1\":{}, \"add2\":{}, \"add3\":{}, \"add4\":{}, \"add5\":null,\"add6\":\"sdfsdf\",\"contact2\":{}, \"number\":30,\"height\":\" 33.24 \",\"name\":\"PengtaoQiu\nAlvin\",\"type\":null,\"weight\":40.3}";
   SimpleObj temp = Json.toObject(jsonStr, SimpleObj.class);
   Assert.assertThat(temp.getName(), is("PengtaoQiu\nAlvin"));
   Assert.assertThat(temp.getId(), is(33442));
   Assert.assertThat(temp.getWeight(), is(40.3F));
   Assert.assertThat(temp.getHeight(), is(33.24));
 }
Esempio n. 2
0
  @Test
  public void test() {
    SimpleObj i = new SimpleObj();
    i.setAge(10);
    i.setId(33442);
    i.setNumber(30);
    i.setName("PengtaoQiu\nAlvin");
    i.setType((short) -33);
    i.setWeight(55.47f);
    i.setHeight(170.5);
    String jsonStr = Json.toJson(i);

    SimpleObj i2 = Json.toObject(jsonStr, SimpleObj.class);
    Assert.assertThat(i2.getAge(), is(10));
    Assert.assertThat(i2.getId(), is(33442));
    Assert.assertThat(i2.getNumber(), is(30));
    Assert.assertThat(i2.getDate(), is(0L));
    Assert.assertThat(i2.getName(), is("PengtaoQiu\nAlvin"));
    Assert.assertThat(i2.getType(), is((short) -33));
    Assert.assertThat(i2.getHeight(), is(170.5));
    Assert.assertThat(i2.getWeight(), is(55.47f));
  }