BookingMessageTO { public String toJson() { try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { new BookingMessageTOWriter().writeTo(this, null, null, null, MediaType.APPLICATION_JSON_TYPE, null, bos); bos.flush(); return bos.toString(StandardCharsets.UTF_8.name()); } catch (IOException e) { throw new RuntimeException("Cannot convert " + this + " to JSON", e); } } BookingMessageTO(Long guest, String room, LocalDate checkin, LocalDate checkout); Long getGuest(); String getRoom(); LocalDate getCheckin(); LocalDate getCheckout(); @Override String toString(); static BookingMessageTO fromJson(String json); String toJson();  }
@Test public void toJson() { LocalDate aDate = LocalDate.of(2014, Month.NOVEMBER, 25); String generatedjson = new BookingMessageTO(12L, "abc", aDate, aDate).toJson(); assertThat(generatedjson, is(equalTo(JSON))); }