-
Postman Unsupported Media Type 에러SOLUX-우리만 앱 2021. 8. 6. 18:37
스프링 시큐리티와 OAuth2를 이용하여 로그인 기능을 구현했고,
그 후 User entity와 Notice 엔티티를 조인하는 과정 중에 계속 발생한 에러다.
이미 Notice 엔티티에는 Club 엔티티를 join 해놓은 상태였다.
@NoArgsConstructor @Getter @Entity public class Notice extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(length = 500, nullable = false) private String title; @Column(columnDefinition = "TEXT", nullable = false) private String content; private String author; @JsonBackReference @ManyToOne @JoinColumn(name = "Club_ID") private Club club; @JsonBackReference @ManyToOne @JoinColumn(name = "User_ID") private User user; @Builder public Notice(String title, String content, String author , Club club) { this.title = title; this.content = content; this.author = author; this.club = club; } public void update(String title, String content) { this.title = title; this.content = content; } }
이렇게 한 후 postman에서 notice를 post 했더니 지원하지 않는 미디어 타입이라는 에러가 나왔다.
하지만
@JsonIgnore @ManyToOne @JoinColumn(name = "User_ID") private User user;
@JsonBackReference 대신 @JsonIgnore을 사용했더니 오류가 발생하지 않았다.
@JsonIgnore을 사용하면 Notice를 조회할 때 User 정보는 json으로 보여주지 않는다.
@JsonBackReference가 2개라서 오류가 발생하는지 알아보려고 Club에 @JsonBackReference 대신 @JsonIgnore을 사용하고, User에 @JsonBackReference를 사용해봤더니 이때도 동일하게 415 에러가 뜨는 걸 알 수 있었다.
아마 User 정보에 이름을 받아와서 표시해주는 과정에서 발생한 오류인 것 같다.
'SOLUX-우리만 앱' 카테고리의 다른 글
aws EC2 서버 접속 (0) 2021.08.12 JPA 순환 참조 해결 (0) 2021.08.08 #2 ERD (0) 2021.07.13 #1 조별 일지 기록 페이지 (0) 2021.07.05 JPA란? (0) 2021.07.05