Search in sources :

Example 1 with EventWithLocalDateTime

use of com.baeldung.jackson.date.EventWithLocalDateTime in project tutorials by eugenp.

the class JacksonDateUnitTest method whenSerializingJava8DateWithCustomSerializer_thenCorrect.

@Test
public void whenSerializingJava8DateWithCustomSerializer_thenCorrect() throws JsonProcessingException {
    final LocalDateTime date = LocalDateTime.of(2014, 12, 20, 2, 30);
    final EventWithLocalDateTime event = new EventWithLocalDateTime("party", date);
    final ObjectMapper mapper = new ObjectMapper();
    final String result = mapper.writeValueAsString(event);
    assertThat(result, containsString("2014-12-20 02:30"));
}
Also used : LocalDateTime(java.time.LocalDateTime) EventWithLocalDateTime(com.baeldung.jackson.date.EventWithLocalDateTime) EventWithLocalDateTime(com.baeldung.jackson.date.EventWithLocalDateTime) Matchers.containsString(org.hamcrest.Matchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

EventWithLocalDateTime (com.baeldung.jackson.date.EventWithLocalDateTime)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LocalDateTime (java.time.LocalDateTime)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1