Esempio n. 1
0
  @Test
  public void testDateSerialization() {
    GsonAdapter adapter = new GsonAdapter();
    Gson gson = adapter.createGson();

    Date date = new Date();
    String time = Integer.toString((int) (date.getTime() / 1000));
    assertEquals(time, gson.toJson(date));
  }
Esempio n. 2
0
  @Test
  public void testDateDeserialization() {
    GsonAdapter adapter = new GsonAdapter();
    Gson gson = adapter.createGson();

    Date date = new Date(12345000);
    TestObj obj = gson.fromJson("{\"some_date\":12345}", TestObj.class);

    assertEquals(date, obj.getSomeDate());
  }
Esempio n. 3
0
  @Test
  public void testCamelCase() {
    GsonAdapter adapter = new GsonAdapter();
    Gson gson = adapter.createGson();

    Offer offer = new Offer();
    offer.setAmount(199);
    offer.setInterval(Interval.WEEK);
    offer.setName("Superabo");
    offer.setTrialPeriodDays(15);

    String json = gson.toJson(offer);
    assertEquals(
        "{\"name\":\"Superabo\",\"amount\":199,\"interval\":\"week\",\"trial_period_days\":15}",
        json);
  }