Use milliseconds as default Instant serialization/deserialization
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Armin Friedl 2020-06-21 17:32:56 +02:00
parent 5c976fc9d9
commit 23af542178
Signed by: armin
GPG key ID: 48C726EEE7FBCBC8
5 changed files with 21 additions and 22 deletions

View file

@ -7,7 +7,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@Configuration @Configuration
public class FlingConfiguration { public class FlingConfiguration {
@ -18,8 +22,13 @@ public class FlingConfiguration {
@Bean @Bean
public ObjectMapper objectMapper() { public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper()
objectMapper.setSerializationInclusion(Include.NON_ABSENT); .setSerializationInclusion(Include.NON_ABSENT)
.registerModule(new JavaTimeModule())
// Handle instant as milliseconds
.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false)
.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
return objectMapper; return objectMapper;
} }
} }

View file

@ -23,11 +23,4 @@ public class ArtifactDto {
private Instant uploadTime; private Instant uploadTime;
private FlingDto fling; private FlingDto fling;
@JsonProperty("uploadTime")
public Long getJsonUploadTime() {
if(uploadTime == null) return null;
return uploadTime.toEpochMilli();
}
} }

View file

@ -93,9 +93,4 @@ public class FlingDto {
return expiration; return expiration;
} }
@JsonProperty("creationTime")
public Long getJsonUploadTime() {
return creationTime.toEpochMilli();
}
} }

View file

@ -5,6 +5,7 @@ spring:
username: sa username: sa
password: password:
jpa: jpa:
open-in-view: false
hibernate.ddl-auto: update hibernate.ddl-auto: update
database-platform: org.hibernate.dialect.H2Dialect database-platform: org.hibernate.dialect.H2Dialect
servlet: servlet:

View file

@ -5,6 +5,7 @@ spring:
username: sa username: sa
password: password:
jpa: jpa:
open-in-view: false
hibernate.ddl-auto: update hibernate.ddl-auto: update
database-platform: org.hibernate.dialect.H2Dialect database-platform: org.hibernate.dialect.H2Dialect
servlet: servlet: