Back-End/Spring
[Spring] cannot deserialize from Object value (no delegate- or property-based Creator) 에러
미피뿌
2022. 6. 13. 12:34
반응형
cannot deserialize from Object value
(no delegate- or property-based Creator)
Domain Class
public class Product {
private Long id;
private String name;
private String maker;
private Integer price;
private String imageUrl;
public Product(String name, String maker, int price) {
this.name = name;
this.maker = maker;
this.price = price;
}
}
ProductControllerTest
@WebMvcTest(ProductController.class)
class ProductControllerTest {
@Test
void create() throws Exception {
mockMvc.perform(post("/products")
.contentType(MediaType.APPLICATION_JSON)
.content("{\"name\":\"냥냥\",\"maker\":\"냥이월드\",\"price\":5000}"))
.andExpect(status().isCreated());
}
}
에러 원인
jackson library가 빈 생성자가 없는 모델을 생성하는 방법을 모르기 때문
해결방안
Domain class (Member Class) 에 빈 생성자 추가
public class Product {
private Long id;
private String name;
private String maker;
private Integer price;
private String imageUrl;
// 빈 생성자 추가
public Product() {
}
public Product(String name, String maker, int price) {
this.name = name;
this.maker = maker;
this.price = price;
}
}
반응형