Пример #1
0
  @Test
  public void testNotification() {
    final JsonBuilder jb = new JsonBuilder();
    final String randomId = UUID.randomUUID().toString();
    final Notification notification =
        new Notification() {
          @Override
          public String getId() {
            return randomId;
          }

          @Override
          public Date getCreated() {
            return new Date(0);
          }
        };
    notification.setMessage("Test message.");
    // Get JSON
    final ObjectNode json = jb.toJson(notification);
    assertThat(json.get("id")).isNotNull();
    assertThat(json.get("id").asText()).isEqualTo(notification.getId());
    assertThat(json.get("read")).isNotNull();
    assertThat(json.get("read").asBoolean()).isEqualTo(false);
    assertThat(json.get("message")).isNotNull();
    assertThat(json.get("message").asText()).isEqualTo(notification.getMessage());
    assertThat(json.get("timestamp")).isNotNull();
    assertThat(json.get("timestamp").asText())
        .isEqualTo(ISO8601Utils.format(notification.getCreated(), true, TimeZone.getDefault()));
  }
Пример #2
0
 /** {@inheritDoc} */
 @Override
 public void serialize(final Date date, final JsonGenerator gen, final SerializerProvider provider)
     throws IOException {
   if (date == null) {
     gen.writeString((String) null);
   } else {
     gen.writeString(ISO8601Utils.format(date, true));
   }
 }