Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 코드스테이츠 #
- 인터넷 #ISP
- 사용자계정 #WSL2
- git #intellij
- 공부방식
- Git #회고록
- 글 foramt
- 회고록
- WSL2 #권한
- 회고 #주간회고
- 에러해결
- Java환경
- 회고록_코드스테이츠
- JAVA기본
- jvm
- 백엔드로드맵
- 몰입학습 #몰입
- 코딩테스트
- 네트워크 기초
- 피드백
- mapstruct
- 회고
- 롤중독
- 시작 #꾸준히 #과하지않게
- WSL #Linux #ubuntu
- 정리글 작성법
- String
- 호스트주소 #Host주소
- 코드스테이츠 #회고록
- OOP
Archives
- Today
- Total
느리더라도 꾸준히
[에러해결][Mapstruct]org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation 본문
Spring
[에러해결][Mapstruct]org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
테디규 2023. 2. 21. 10:24문제상황
MVC 패턴의 Mapstruct를 이용한 Mapper를 이용하는 도중 해당 에러가 발생하였다.
@RestController
@RequestMapping("/answers")
@RequiredArgsConstructor
public class AnswerController {
private final AnswerService answerService;
private final AnswerMapper answerMapper;
@PostMapping
public ResponseEntity postAnswer(@RequestBody AnswerDto.Post postDto){
Answer findAnswer = answerService.createAnswer(answerMapper.answerPostDtoToAnswer(postDto));
return new ResponseEntity(answerMapper.answerToAnswerResponseDto(findAnswer), HttpStatus.CREATED);
}
}
PostDto로 요청 메시지를 받아 엔티티로 변환하고, 엔티티를 ResponseDto로 변환하여 출력하는 소스 코드이다.
@Setter
public static class Response{
private Long answerId;
private Long score;
private Boolean isAccepted;
private String content;
}
Dto는 다음과 같다.
해결 방법
디버깅해보니, 응답해보는 과정에서 발생하는 에러였다.
ResponseEntity 에 들어오는 객체를 변환하는 과정에서 Getter 가 필요한데 내 Response Dto 코드에는 @Getter가 없어서 발생하는 문제였다.
Response 에 @Getter를 추가해주자.
출처
'Spring' 카테고리의 다른 글
[Mapstruct] uses = 옵션 사용 ( 다른 엔티티 DTO들 간의 Mapper 메서드 공유하기 ) (0) | 2023.02.22 |
---|
Comments