본문 바로가기
Spring

[Spring/Error] No serializer found for class

by clolee 2023. 10. 10.

 

오류 :

No serializer found for class ... and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

 

  • Serialize : Object to JSON 
  • Deserialize : JSON to Object 

 

 the default configuration of an ObjectMapper instance is to only access properties that are public fields or have public getters/setters. 

 

Jackson 라이브러리의 ObjectMapper는 Serialize 할 때 접근 제한자가 public이거나 Getter/Setter를 이용.

필드가 private로 선언되어있으면 JSON 변환 과정에서 문제가 발생한다

 

 

해결 방법 :

해당 클래스 dto 에 @Getter 어노테이션 추가

 

참고 :

https://taengsw.tistory.com/50

https://velog.io/@maketheworldwise/Jackson-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EB%B0%94%EC%9D%B8%EB%94%A9-%EC%97%90%EB%9F%AC-InvalidDefinitionException-No-serializer-found-for-class

https://velog.io/@poogie/No-serializer-found-for-class-%EC%98%A4%EB%A5%98

https://stackoverflow.com/questions/8367312/serializing-with-jackson-json-getting-no-serializer-found

 

댓글