From dde18a72a4c06fcc337a6572badd265709582510 Mon Sep 17 00:00:00 2001 From: jimmy0524 <10jmin04@naver.com> Date: Tue, 24 Dec 2024 17:13:36 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20beforeTimestamp=20null=20=EB=B0=A9?= =?UTF-8?q?=EC=A7=80=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/chat/service/ChatServiceImpl.java | 4 ++++ .../api/chat/service/WebhookServiceImpl.java | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java b/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java index a788033..7615f59 100644 --- a/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java @@ -103,6 +103,10 @@ public List getChatList(String beforeTimestamp, String use } ChatInfoList webhookResult = webhookService.sendWebhookForChatList(activeChatIdsByUserId, beforeTimestamp); + if (webhookResult == null || webhookResult.getChatInfoList() == null || webhookResult.getChatInfoList().isEmpty()) { + return Collections.emptyList(); + } + List chatInfoList = webhookResult.getChatInfoList(); return chatInfoList.stream().map(chatInfo -> { diff --git a/src/main/java/site/billbill/apiserver/api/chat/service/WebhookServiceImpl.java b/src/main/java/site/billbill/apiserver/api/chat/service/WebhookServiceImpl.java index c73f03e..3fba597 100644 --- a/src/main/java/site/billbill/apiserver/api/chat/service/WebhookServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/chat/service/WebhookServiceImpl.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,10 +25,11 @@ public class WebhookServiceImpl implements WebhookService { @Autowired public WebhookServiceImpl(@Value("${webhook.url}") String webhookUrl, - WebClient.Builder webClientBuilder, - ObjectMapper objectMapper) { + WebClient.Builder webClientBuilder) { this.webClient = webClientBuilder.baseUrl(webhookUrl).build(); - this.objectMapper = objectMapper; + this.objectMapper = new ObjectMapper(); + this.objectMapper.registerModule(new JavaTimeModule()); // Java 8 시간 타입 지원 + this.objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // 배열 대신 ISO-8601 사용 } public void sendWebhookForChatRoomCreate(String channelId, String contact, String owner) { @@ -49,6 +52,9 @@ public void sendWebhookForChatRoomCreate(String channelId, String contact, Strin } public WebhookRequest.ChatInfoList sendWebhookForChatList(List chatRoomIds, String beforeTimestamp) { + if (beforeTimestamp == null) { + beforeTimestamp = ""; + } String jsonResponse = webClient.post() .uri("/chat/list") .bodyValue(Map.of( @@ -58,10 +64,13 @@ public WebhookRequest.ChatInfoList sendWebhookForChatList(List chatRoomI .retrieve() .bodyToMono(String.class) .block(); + log.info(jsonResponse.toString()); try { - return objectMapper.readValue(jsonResponse, WebhookRequest.ChatInfoList.class); + WebhookRequest.ChatInfoList result = objectMapper.readValue(jsonResponse, WebhookRequest.ChatInfoList.class); + return result; } catch (JsonProcessingException e) { - throw new RuntimeException(e); + throw new RuntimeException("JSON Parsing Error", e); } + } }