com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.example.iworks.domain.address.dto.AddressOrgChartResonseDto and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.HashMap["data"])
Jackson databind에서는 public 필드 또는 getter 메소드가 존재하는 필드에만 동작하게 되어있다. 즉, 저 오류가 떴다는 것은 private 필드에 대한 getter 메소드가 없는 경우를 의미한다.
public class AddressOrgChartResonseDto {
private final String departmentName; // 접근 불가능
private final Integer departmentId;
public AddressOrgChartResonseDto(Department department){
this.departmentId=department.getDepartmentId();
this.departmentName=department.getDepartmentName();
}
}
private 값에 접근할 수 있도록 @Getter 어노테이션을 추가한다.