끊임없이 검증하라

나에게 당연할지라도

Debug

Debug_1_InvalidDefinitionException

fadet 2022. 5. 12. 16:45

※ 이 포스트는 실습 과정에서 디버깅한 직후 과정 기록을 위해서만 작성하므로 정말 단순 참고용으로만 봐주세요.

다른 포스트들과 달리 글을 다듬지 않아 많이 투박할 수 있습니다.

궁금한 사항이나 틀린 내용이 있다면 알려주시면 감사하겠습니다.

 


해당 포스트가 작성되는 글의 서두에도 작성되어 있지만 정말 디버깅 과정만 기록하는 카테고리입니다. txt에 따로 메모는 해두는데 한 줄로 남겨놓으면 나중에 까먹어서 다시 찾아보는.... 여튼 첫 글은 

InvalidDefinitionException: (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

에 대해서입니다.

 

# 상황 및 발생 버그

- 타임리프로 포스트 목록 페이지를 만들고 컨트롤러에 연결 후 잘 되나 확인하려고 톰캣 실행

- InvalidDefinitionException: (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator) 발생

 

# 원인 예상

- 발생한 예외는 InvalidDefinitionException로 구글링 해보니 직렬화나 JSON 파싱 과정에서 잘 발생한다고 함

- 로그를 쭉 해석해보니 기본 생성자가 없다고 역직렬화를 할 수 없다고 하는 듯

 

# 해결

- 찾아보니 JAVA <-> JSON 파싱 라이브러리인 Jackson library는 빈 생성자를 만들 줄 모른다고 합니다. 그래서 템플릿과 연결된 Dto를 살펴보니 코드 작성 과정 중에서 @NoArgsArgument 가 빠져 있었네요...

@Getter
public class LinkSaveRequestDto {
	...
    public LinkSaveRequestDto(String postNum, String githubRepo, String title, String stackCategory, String description, Long importance) {
        this.postNum = postNum;
        this.githubRepo = githubRepo;
        this.title = title;
        this.stackCategory = stackCategory;
        this.description = description;
        this.importance = importance;
    }

    public Link toEntity() {
        return new Link(title, stackCategory, description, postNum, githubRepo, importance);
    }
}

코드 작성 과정에서 final을 사용할 수 없는 상황이 있어서 @RequiredArgsConstructor랑 @NoArgsConstructor를 지우고 생성자 코드를 작성해놨었는데 그것때문에 빈 생성자 코드가 없어서 그랬었나봅니다.

 

@Getter
@NoArgsConstructor // 추가
public class LinkSaveRequestDto {
...

그래서 @NoArgsConstructor로 빈 생성자 추가해주니 간단히 해결


refer

https://stackoverflow.com/questions/53191468/no-creators-like-default-construct-exist-cannot-deserialize-from-object-valu

 

No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator

I am trying to consume an API using Retrofit and Jackson to deserialize. I am getting the onFailure error No Creators, like default construct, exist): cannot deserialize from Object value (no deleg...

stackoverflow.com

 

'Debug' 카테고리의 다른 글

(내가 방치했던)토이 프로젝트 되살리기  (0) 2023.09.16