Error

[Error] java.util.LinkedHashMap cannot be cast to class

오선지♬ 2024. 9. 4. 19:50
728x90
반응형

Service Error:

서비스파일명, 함수명,Unrecognized field "필드명" (DTO파일명), not marked as ignorable (7 known properties: ....)

 

이 오류는 Unrecognized field "createdAt"JSON 응답에  해당 속성이 없는 이름이 지정된 필드가 포함되어 있음을 나타냅니다.

 

해결책

JSON 응답 필드와 DTO 클래스의 필드 간의 불일치를 처리해야 합니다.

 

1. DTO에 누락된 필드 추가

createdAt클래스 에 필드가 있어야 하는 경우 ResYhIftkUserApiListDTO다음과 같이 추가해야 합니다.

 

2. 인식되지 않는 필드 무시

DTO 클래스에 정의되지 않은 필드를 무시하려면 Jackson을 구성하여 알 수 없는 속성을 무시할 수 있습니다. DTO 클래스에 주석을 달거나 .을 구성하여 이를 수행할 수 있습니다 ObjectMapper.

 DTO 클래스에 주석 달기

@JsonIgnoreProperties클래스 에 주석을 추가하세요 ResYhIftkUserApiListDTO:

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ResYhIftkUserApiListDTO extends ResBaseDTO implements Serializable {
    // existing fields and methods
}​

 
728x90
반응형