-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
97 additions
and
66 deletions.
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/dnd/runus/global/constant/TimeConstant.java
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,16 @@ | ||
package com.dnd.runus.global.constant; | ||
|
||
import java.time.ZoneId; | ||
|
||
public final class TimeConstant { | ||
TimeConstant() {} | ||
|
||
public static final String TIME_FORMAT = "HH:mm:ss"; | ||
public static final String TIME_FORMAT_EXAMPLE = "01:23:34"; | ||
public static final String DATE_FORMAT = "yyyy-MM-dd"; | ||
public static final String DATE_FORMAT_EXAMPLE = "2024-01-12"; | ||
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; | ||
public static final String DATE_TIME_FORMAT_EXAMPLE = "2024-01-12 01:23:34"; | ||
public static final String SERVER_TIMEZONE = "Asia/Seoul"; | ||
public static final ZoneId SERVER_TIMEZONE_ID = ZoneId.of(SERVER_TIMEZONE); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/dnd/runus/presentation/config/ObjectMapperConfig.java
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 |
---|---|---|
@@ -1,16 +1,47 @@ | ||
package com.dnd.runus.presentation.config; | ||
|
||
import com.fasterxml.jackson.databind.Module; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.*; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.time.*; | ||
|
||
import static com.dnd.runus.global.constant.TimeConstant.*; | ||
import static java.time.format.DateTimeFormatter.ofPattern; | ||
|
||
@Configuration | ||
public class ObjectMapperConfig { | ||
@Bean | ||
ObjectMapper objectMapper() { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new JavaTimeModule()); | ||
|
||
DateTimeFormatter dateFormatter = ofPattern(DATE_FORMAT); | ||
DateTimeFormatter dateTimeFormatter = ofPattern(DATE_TIME_FORMAT); | ||
|
||
Module dateTimeModule = new SimpleModule() | ||
.addSerializer(LocalTime.class, new LocalTimeSerializer(ofPattern(TIME_FORMAT))) | ||
.addSerializer(LocalDate.class, new LocalDateSerializer(dateFormatter)) | ||
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(dateTimeFormatter)) | ||
.addSerializer( | ||
OffsetDateTime.class, | ||
new OffsetDateTimeSerializer( | ||
OffsetDateTimeSerializer.INSTANCE, false, false, dateTimeFormatter) {}) | ||
.addSerializer( | ||
Instant.class, | ||
new InstantSerializer( | ||
InstantSerializer.INSTANCE, | ||
false, | ||
false, | ||
dateTimeFormatter.withZone(SERVER_TIMEZONE_ID)) {}); | ||
|
||
objectMapper.registerModule(dateTimeModule); | ||
|
||
return objectMapper; | ||
} | ||
} |