-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 + | ||
'}'; | ||
} | ||
} | ||
|
||
|
||
} |