Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3e6c5b2

Browse files
docs: 빈 리스트와 not null 타입 간의 직렬화 문제
1 parent 9db8d59 commit 3e6c5b2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## 빈 리스트와 not null 타입 간의 직렬화 문제
2+
3+
#### 개요
4+
이번에는 레디스와 코틀린을 동시에 사용하면서 생겼던 문제에 대해 다뤄봅니다.
5+
6+
#### 무슨 문제인가요?
7+
레디스에서 값을 저장할 때 기본 타입이 아니라면 그 타입을 저장하기 위해서 직렬화를 수행합니다.
8+
그 중 디폴트로 적용되는 직렬화는 빈 리스트를 빈 리스트 자체로 저장하는 것이 아니라
9+
빈 리스트를 null로 변환하여 저장합니다.
10+
11+
문제는 여기서 발생하게 됩니다.
12+
코틀린에는 not null 타입이 존재합니다. (물론 다른 언어에도 있지만)
13+
그런데 레디스에서 빈 리스트를 null로 저장하니
14+
다시 역직렬화를 했을 때 빈 리스트는 null이 되어 객체에 저장됩니다.
15+
이때 리스트가 not null 타입이었다면 의도치 않게 `NullPointerException`이 발생하게 됩니다.
16+
17+
#### 해결 방법
18+
레디스의 디폴트 직렬화 방법을 채택하지 않고 Jackson 직렬화 등의 다른 방식을 채택해야합니다.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /