-
Notifications
You must be signed in to change notification settings - Fork 0
LocalDateTime 저장 에러 해결하기
Lucy Oh edited this page Aug 10, 2023
·
1 revision
Written By Jisoo Oh
LocalDateTime을 DynamoDB에 저장하려고 했으나, 다음과 같은 에러가 발생함.
InvalidDefinitionException: Joda date/time type `org.joda.time.LocalDateTime` not supported by default
- DateTime도 동일한 오류 발생
LocalDateTime parsing 에러로 추측 → 직접 LocalDateTime을 바꿔주는 Custom Converter를 작성함.
public static class LocalDateTimeConverter implements DynamoDBTypeConverter<Date, LocalDateTime> {
@Override
public Date convert(LocalDateTime source) {
return Date.from(source.toInstant(ZoneOffset.UTC));
}
@Override
public LocalDateTime unconvert(Date source) {
return source.toInstant().atZone(TimeZone.getDefault().toZoneId()).toLocalDateTime();
}
}
이후, 사용하고자 하는 Entity의 attribute위에 추가해줌!
- BaseEntity의 LocalDateTime attribute에@DynamoDBTypeConverted(converter = LocalDateTimeConverter.class) 애노테이션 추가해줌.
public class BaseEntity {
...
@LastModifiedDate
@DynamoDBAttribute
@DynamoDBTypeConverted(converter = LocalDateTimeConverter.class)
private LocalDateTime lastModifiedDate;
...
}