Response Entity에서 null을 반환하는 경우

Adam·2024년 9월 4일
0

트러블슈팅

목록 보기
6/8

인앱결제를 구현하면서 영수증 검증 서버로 자바 스프링을 사용했다.
그 중 한개의 API에서 DB에서 미리 등록한 상품 목록을 조회하는 것이 있었는데, DB에서 분명 해당 조건에 맞는 데이터가 있었지만 계속 빈 배열을 반환하는 오류가 있었다.

public ResponseEntity<List> getSubscriptionProductList() {

    List<SubcscriptionProductResponse> response = subscriptionProductRepository.findAllByStatus("ACTIVE").stream()
            .map(product -> SubcscriptionProductResponse.builder()
                    .storeType(product.getStoreType())
                    .productId(product.getProductId())
                    .purchaseType(product.getPurchaseType())
                    .build())
            .collect(Collectors.toList());
    return ResponseEntity.ok(response);
}

리스폰스 객체는 다음과 같았다.

  @Schema(description = "구독 상품 정보")
@Builder
public class SubcscriptionProductResponse {
    @Schema(description = "애플리케이션 식별자", example = "com.example")
    private String appIdentifier;

    @Schema(description = "플랫폼 유형", example = "GOOGLE_PLAY/APP_STORE")
    private String storeType;

    @Schema(description = "상품ID", example = "PRODUCT_ID")
    private String productId;

    @Schema(description = "제품 유형", example = "SUBSCRIPTION")
    private SubscriptionProduct.PurchaseType purchaseType;
}

GPT가 쉽게 잡아줄 수 있는 애러일 것이라 생각해 물어봤는데 계속 로그만 찍어보라는 말만 반복함

스택오버플로우에 비슷한 케이스가 있었는데 Response에 @Getter가 없을 시 리스폰스에 담지 못했음.
이와 마찬가지로 스웨거 문서에도 해당 리스폰스값이 보이지 않던것이 보이기 시작

추출 후 결과 값은 다음과 같았다

[
  {
      "appIdentifier": null,
      "storeType": "GOOGLE_PLAY",
      "productId": "com.example",
      "purchaseType": "SUBSCRIPTION"
  }
]

교훈

앞으로 꼭 반환하는 객체에는 @Getter을 추가해주자...

profile
Keep going하는 개발자

0개의 댓글