Skip to content

Conversation

sweetykr7
Copy link
Contributor

Pull Request

Issues

Resolves #73
Resolves #75
Resolves #76

Description

How Has This Been Tested?

  • 테스트 환경: OpenJDK 21(Amazon Corretto 21), kotest (mockk 라이브러리) with FreeSpec.

@sweetykr7 sweetykr7 added type: feature 새로운 기능 또는 기능적 개선 A new feature or enhancement in: board Issues in the board module review: ing Reviews are in progress and taking time labels Mar 1, 2025
@merge-simpson
Copy link
Member

Comment on lines +10 to +23
@TestConfiguration
class JacksonTestConfig {
@Bean
fun objectMapper(): ObjectMapper {
return ObjectMapper()
.registerModule(JavaTimeModule())
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
}

@Bean
fun mappingJackson2HttpMessageConverter(objectMapper: ObjectMapper): MappingJackson2HttpMessageConverter {
return MappingJackson2HttpMessageConverter(objectMapper)
}
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 이 설정 파일이 명시적으로 필요한 이유가 무엇인가요?

이 설정 파일이 어떨 때 필요하고, 있을 때와 없을 때 어떤 차이가 있는지 궁금합니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merge-simpson 바쁜 와중에도 질문 남겨주셔서 감사합니다.

메인 프로젝트의 Jackson 설정이 테스트 환경에 적용되지 않는 문제를 해결하기 위해,
테스트 환경에서도 동일한 설정이 유지되도록 ObjectMapper와 MappingJackson2HttpMessageConverter를 수동으로 @bean 등록하였습니다.

  • ObjectMapper 설정
    • registerModule(JavaTimeModule()) → 날짜 타입 변환을 지원하도록 설정
    • setSerializationInclusion(JsonInclude.NON_NULL) → null 값이 JSON 직렬화되지 않도록 설정
  • MappingJackson2HttpMessageConverter 등록 이유
    • HTTP 요청/응답 변환 시, 등록한 ObjectMapper가 사용되도록 설정

이 설정 파일은 컨트롤러 테스트에서 활용하는 것이 적절해 보이며, 이를 적용하면 HTTP 통신 테스트에서 null 값이 JSON 직렬화되지 않는 차이가 있습니다.

Copy link
Contributor

@github-insu github-insu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍작업하시느라 고생많으셨습니다~
설정과 관련된 코드를 Test 진행하는 코드와 분리해 작성해주셨군요! 다른 테스트 코드에서도 이 설정이 필요하다면 @Import를 이용해서 쉽게 사용할 수 있을 것 같습니다~! 감사합니다~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: board Issues in the board module review: ing Reviews are in progress and taking time type: feature 새로운 기능 또는 기능적 개선 A new feature or enhancement
Projects
None yet
5 participants