diff --git a/src/main/java/com/gdschongik/gdsc/global/config/ObjectMapperConfig.java b/src/main/java/com/gdschongik/gdsc/global/config/ObjectMapperConfig.java index 34d3e7637..b4aae9ed9 100644 --- a/src/main/java/com/gdschongik/gdsc/global/config/ObjectMapperConfig.java +++ b/src/main/java/com/gdschongik/gdsc/global/config/ObjectMapperConfig.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; @@ -28,7 +28,7 @@ public class ObjectMapperConfig { @Bean public ObjectMapper objectMapper() { ObjectMapper mapper = new ObjectMapper(); - SimpleModule module = new SimpleModule(); + JavaTimeModule module = new JavaTimeModule(); // LocalDate module.addSerializer(LocalDate.class, new LocalDateSerializer()); @@ -43,6 +43,7 @@ public ObjectMapper objectMapper() { module.addDeserializer(LocalTime.class, new LocalTimeDeserializer()); // ZonedDateTime + module.addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer()); module.addDeserializer(ZonedDateTime.class, new ZonedDateTimeDeserializer()); mapper.registerModule(module); @@ -114,6 +115,15 @@ public LocalTime deserialize(JsonParser jsonParser, DeserializationContext deser } } + public class ZonedDateTimeSerializer extends JsonSerializer { + @Override + public void serialize(ZonedDateTime value, JsonGenerator generator, SerializerProvider serializers) + throws IOException { + generator.writeString( + value.format(DateTimeFormatter.ofPattern(DATETIME).withZone(ZoneId.of("Asia/Seoul")))); + } + } + public class ZonedDateTimeDeserializer extends JsonDeserializer { @Override public ZonedDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)