개발/Spring

InvalidDefinitionException 에러

IamBD 2022. 6. 8. 17:55

WebClient를 사용하여 크롤링할 데이터를 받는 도중 InvalidDefinitionException 에러가 발생했다.

 

에러 로그를 읽어보니 기본 생성자가 없다고 나오고 관련 검색을 해봐도 기본 생성자를 생성해봐라! 라는 답변이었다.

이는 불변 객체를 선언하고 싶은 나에게는 맞지 않는 해답이기 때문에 더 찾아보니

@JsonCreateor와 @JsonProperty를 사용하는 방법을 찾았고 다음과 같이 수정 후 정상 작동하는것을 확인했다.

 

 

참고

https://www.baeldung.com/jackson-deserialize-immutable-objects

 

Deserialize Immutable Objects with Jackson | Baeldung

Learn how to use Jackson to deserialize immutable objects

www.baeldung.com

https://blog.benelog.net/jackson-with-constructor.html

 

으로 파싱한 JSON 속성값을 생성자로 전달하기 - 개발수양록

파싱하고자하는 JSON { "accessDateTime": "2019-10-10T11:14:16Z", "ip": "175.242.91.54", "username": "benelog" } 위와 같은 JSON을 파생해서 아래와 같이 setter가 없는 객체에 집어 넣고 싶은 경우가 있습니다. 파싱한 결

blog.benelog.net

 

'개발 > Spring' 카테고리의 다른 글

[Spring] json deserialize ClassCastException  (0) 2022.06.16
Spring Data JPA - 2  (0) 2022.02.25
Spring Data JPA - 1  (0) 2022.02.24