Json 데이터 보내기 POST

yesrin·2023년 7월 19일

TIL

목록 보기
9/15

내가 보내고 싶은 Request의 형태가 아래와 같다면?

{
    "ProductList": [
        {
            "imageUrl": "",
            "productName": "짜장면",
            "price": "8000",
            "description": "description"
        },
        {
            "imageUrl": "",
            "productName": "짬뽕",
            "price": "8000",
            "description": "description"
        }
    ]
}

ProductRequestDto.java

@Getter
public class ProductRequestDto {
    private String imageUrl;
    private String productName;
    private int price;
    private String description;
}

ProductRequestListDto.java

@Getter
public class ProductRequestListDto {

    public List<ProductRequestDto> ProductList= new ArrayList<>();

}

반복되는 부분이 있는 경우 Dto를 나누어 작성해 줍니다.

주의!
POSTMAN에서 보내줄때 ProductList 이름을 맞춰 줍니다.

컨트롤러단에서 발생하는 다른 오류 참고
(out of START_ARRAY token)
https://sudo-minz.tistory.com/63

profile
안녕하세요! 틀린 정보는 댓글 달아 주세요.

0개의 댓글