diff --git a/build.gradle b/build.gradle index 704a5b36..3c4903a4 100644 --- a/build.gradle +++ b/build.gradle @@ -82,7 +82,7 @@ dependencies { } testImplementation 'org.apache.commons:commons-io:1.3.2' testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.6' - + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.0' } test { diff --git a/src/test/java/com/epam/reportportal/InstantDemoTest.java b/src/test/java/com/epam/reportportal/InstantDemoTest.java new file mode 100644 index 00000000..bc19653c --- /dev/null +++ b/src/test/java/com/epam/reportportal/InstantDemoTest.java @@ -0,0 +1,54 @@ +package com.epam.reportportal; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; +import com.fasterxml.jackson.databind.json.JsonMapper; +import java.time.Instant; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; + +import org.junit.jupiter.api.Test; + +public class InstantDemoTest { + + public static final ObjectMapper MAPPER = JsonMapper.builder() + .addModule(new JavaTimeModule()) + .annotationIntrospector(new JacksonAnnotationIntrospector()) + .configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) + .addModule(new JavaTimeModule()) + .build(); + + @Test + void testInstant() throws JsonProcessingException { + SimpleLaunch launch = new SimpleLaunch(); + + // serialize + String json = MAPPER.writeValueAsString(launch); + System.out.println(json); + + // deserialize + SimpleLaunch deserialized = MAPPER.readValue(json, SimpleLaunch.class); + + System.out.println(deserialized.instant); + } + + private static class SimpleLaunch { + + public Long id = 123L; + public Instant instant = Instant.now(); + + public String toString() { + return "SimpleLaunch{" + + "id=" + id + + ", instant=" + instant + + '}'; + } + } + + +}