강의

멘토링

커뮤니티

Inflearn Community Q&A

inzy4581's profile image
inzy4581

asked

[Revised 2023-11-27] Developing RESTful Web Services using Spring Boot 3.x

Programmatic Filtering - Individual User Lookup

@JsonFilter 적용 후 오류 발생했을 때 response에 {} 가 포함되어 리턴됩니다.

Written on

·

560

0

안녕하세요,

강의 09:35 지점 처럼 @JsonFilter("UserInfo") 적용 후 SimpleBeanPropertyFilter와 FilterProvider를 적용하지 않은 UserController에서 호출했을 때 아래 오류가 발생하는데 

Type definition error: [simple type, class com.study.myrestfulwebservice.user.User]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot resolve PropertyFilter with id 'UserInfo'; no FilterProvider configured

포스트맨에서 응답 body를 확인해보면 아래 스샷처럼 빈 오브젝트가 포함되어서 리턴됩니다. 강제로 throw new RuntimeException을 발생시키면 빈 오브젝트 없이 정상적으로 ErrorResponse 객체에 대해서만 출력됩니다. 빈 오브젝트가 왜 포함되서 리턴되는지 원인을 알 수 없어 문의드립니다 ㅠ_ㅠ 

rest-apispring-boot

Answer 1

0

Dowon Lee님의 프로필 이미지
Dowon Lee
Instructor

안녕하세요, 이도원입니다. 

문의하신 내용에서처럼 EntityModel 객체를 정상적으로 반환할 때는, 문제가 없지만, 오류가 발생한 경우(JsonFilter에 의한 Filter객체를 지정하지 않을 때와 같은)에는 ExceptionResponse 객체를 생성해서 반환하게 됩니다.

<EntityModel/>

<ExceptionResponse>

    <timestamp>2022-04-16T04:31:23.475+00:00</timestamp>

    <message>Type definition error: [simple type, class com.example.myrestfulservices.user.User]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot resolve PropertyFilter with id 'UserInfo'; no FilterProvider configured (through reference chain: org.springframework.hateoas.EntityModel["content"])</message>

    <details>uri=/users/3</details>

</ExceptionResponse>

크롬 웹브라우저의 개발자도구 > 네트워크 탭을 실행한 다음 ,해당 URI를 호출하면 아래와 같은 응답 메시지를 확인하실 수 있습니다. 정상적인 상태라면 EntityModel 객체만을 반환할 것이며, 오류가 발생했다면,  빈 EntityModel 객체와 ExceptionResponse 객체 2개가 함께 반환됩니다.  RuntimeException을 발생 시켰을 경우에는 ExceptionResponse 객체가 생성된 것이 아니니 때문에, 빈 EntityModel 객체 1개만 반환 됩니다.

감사합니다.

inzy4581's profile image
inzy4581

asked

Ask a question