Skip to content

Commit

Permalink
Instant time POC
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Nov 27, 2024
1 parent f627b60 commit 771a404
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/com/epam/reportportal/InstantDemoTest.java
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 +
'}';
}
}


}

0 comments on commit 771a404

Please sign in to comment.