🔥스파르타 TIL (트러블 슈팅)

LocalDateTime을 Redis Cache로 조회 시 직렬화 문제

승승장규 2025. 4. 10. 01:02
public class UserMileageResponseDto {

    private UUID userId;
    private UUID mileageId;
    private Integer count;
    private LocalDateTime updatedAt;

 

위에 객체를 Redis Cache에 적용한 뒤 조회하려는 과정에서 해당 오류가 발생했다.

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: com.taken_seat.auth_service.application.dto.PageResponseDto["content"]
->java.util.Collections$UnmodifiableRandomAccessList[0]->com.taken_seat.auth_service.
application.dto.mileage.UserMileageResponseDto["updatedAt"])​

 

오류를 살펴보니 Jackson JSON 라이브러리가 Java 8의 날짜/시간 타입인 LocalDateTime을 직렬화하는 데 필요한 모듈이 없어서 발생하는 문제였다.

 

오류를 해결하기 위해 build.gradle에 해당 의존성을 추가한 뒤,

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'

 

public class UserMileageResponseDto {

    private UUID userId;
    private UUID mileageId;
    private Integer count;
    
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime updatedAt;

 

응답 객체에 Json 어노테이션을 달아주니 문제가 해결 되었다.

 

생각보다 간단한 문제여서 다행이었다.