-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonConverter.java
More file actions
38 lines (30 loc) · 1.27 KB
/
JsonConverter.java
File metadata and controls
38 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.perfact.be.domain.chat.converter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.perfact.be.domain.chat.exception.ChatHandler;
import com.perfact.be.domain.chat.exception.status.ChatErrorStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class JsonConverter {
private final ObjectMapper objectMapper;
public List<String> parseJsonArray(String content) {
// content가 null이거나 비어있는지 확인
if (content == null || content.trim().isEmpty()) {
log.error("JSON 파싱할 content가 null이거나 비어있음");
throw new ChatHandler(ChatErrorStatus.CHAT_MESSAGE_PARSING_FAILED);
}
try {
// JSON 배열 형태의 문자열을 List<String>으로 변환
List<String> result = objectMapper.readValue(content, List.class);
log.debug("JSON 배열 파싱 완료 - 결과 개수: {}, 결과: {}", result.size(), result);
return result;
} catch (Exception e) {
log.error("JSON 배열 파싱 실패 - content: {}, 에러: {}", content, e.getMessage(), e);
throw new ChatHandler(ChatErrorStatus.CHAT_MESSAGE_PARSING_FAILED);
}
}
}