There was an unexpected error (type=Internal Server Error, status=500).
Could not write JSON: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.ArrayList[0]->Bulletin.Board.domain.posts.Post["createdDate"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.ArrayList[0]->Bulletin.Board.domain.posts.Post["createdDate"])
org.springframework.data.redis.serializer.SerializationException: Could not write JSON: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.ArrayList[0]->Bulletin.Board.domain.posts.Post["createdDate"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.ArrayList[0]->Bulletin.Board.domain.posts.Post["createdDate"])
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.ArrayList[0]->Bulletin.Board.domain.posts.Post["createdDate"])
✨ 해결
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3'
먼저, 에러 로그에 나온대로 "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" 모듈을 dependency에 추가했다.
@JsonSerialize(using= LocalDateTimeSerializer.class)
@JsonDeserialize(using= LocalDateTimeDeserializer.class)
private LocalDateTime createdDate;
@JsonSerialize(using= LocalDateTimeSerializer.class)
@JsonDeserialize(using= LocalDateTimeDeserializer.class)
private LocalDateTime modifiedDate;
@JsonSerialize와 @JsonDeserialize 어노테이션을 붙였다.
@JsonSerialize | using = 사용할 Serializer class 지정 getter 메소드 / 필드 / value classes 에 붙인다. 참고) value classes는 value objects라고도 한다. value classes는 값 집합을 가지고 있고, 로직이 거의 없거나 전혀 없는 객체다. DTO가 value object의 예다. |
@JsonDeserialize | using = 사용할 Deserializer class 지정 setter 메소드 / 필드 / value classes 에 붙인다. |
LocalDateTimeSerializer | Java 8 임시 LocalDateTimes의 Serializer |
LocalDateTimeDeserializer | Java 8 임시 LocalDateTimes의 Deserializer |
참고 👇
https://www.quora.com/What-are-value-classes-in-Java
반응형