Skip to content

Commit

Permalink
fix: LocalDateTime 타입 직렬화/역직렬화 오류로 인한 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kjungw1025 committed Feb 1, 2024
1 parent 8f6088a commit 267d1b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.dku.council.domain.chat.service;

import com.dku.council.domain.chat.model.dto.Message;
import com.dku.council.domain.chat.model.dto.response.ResponseChatDto;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
Expand All @@ -20,6 +21,8 @@ public class MessageReceiver {
public void receiveMessage(String stringChat) throws JsonProcessingException {

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
Message message = objectMapper.readValue(stringChat, Message.class);
log.info("Consumed Message : " + stringChat);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.dku.council.domain.chat.service;

import com.dku.council.domain.chat.model.dto.Message;
import com.dku.council.domain.chat.model.dto.response.ResponseChatDto;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
Expand All @@ -20,6 +21,8 @@ public void send(String topic, Message data) {

// 메시지를 KafkaTemplate 를 사용하여 지정된 토픽으로 전송
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
try {
String stringChat = objectMapper.writeValueAsString(data);
log.info("MessageSender Message -> String형 : " + stringChat);
Expand Down

0 comments on commit 267d1b3

Please sign in to comment.