๊ฐœ๋ฐœ.log/framework

[SpringBoot]Multiple @RequestBody values in one controller method/@RequestBody ์—ฌ๋Ÿฌ ๊ฐœ ์‚ฌ์šฉ/HttpMessageNotReadableException ํ•ด๊ฒฐ

๊ฐœ๋ฐœํ•˜๋Š” ์ฃผ๋””์”จ 2023. 9. 20. 16:02

๋ฌด์ง€์„ฑ์œผ๋กœ ๊ฐœ๋ฐœํ•˜๋‹ค ๋ณด๋‹ˆ,, ์ ์  ๊ธฐ๋ณธ์ ์ธ CS ์ง€์‹๋“ค์„ ์žŠ์–ด๋ฒ„๋ฆฌ๋Š” ๊ธฐ๋ถ„์ด ๋“ค์—ˆ๋‹ค. ๋‹น์—ฐํ•˜๊ฒŒ @RequestBody๋ฅผ ์“ฐ๋˜ ์ค‘ ์ถ”๊ฐ€๋˜๋Š” ์š”๊ฑด์œผ๋กœ ์ ์  DTO๋Š” ๋Š˜์–ด๋‚˜๊ณ ,, @RequestBody๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ์ผ์ด ์ƒ๊ฒผ๋‹ค.

๋ฌธ๋ฒ•์  ์˜ค๋ฅ˜๋Š” ์—†์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ณ„๋‹ค๋ฅธ ์ด์Šˆ๊ฐ€ ์—†์—ˆ๊ณ  API๋ฅผ ์‹คํ–‰ํ•˜๋‹ˆ ํ„ฐ์กŒ๋‹คใ…‹ใ…‹ใ…‹ใ…‹

 

org.springframework.http.converter.HttpMessageNotReadableExcept ion:
Required request body is missing

 

 

ํ•œ๋งˆ๋””๋กœ.. RequestBody๋ฅผ JSONํ˜•์‹์œผ๋กœ ํŒŒ์‹ฑํ•˜์—ฌ ์ธ์‹ํ•˜์ง€ ๋ชปํ–ˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์ƒ์ „ ์ฒ˜์Œ ๋ณด๋Š” ์ด์Šˆ์— ์ด๊ฒŒ ๋ญ์ง€.. ์‹ถ์—ˆ์ง€๋งŒ ์ž์„ธํžˆ ๋ณด๋‹ˆ @RequestBody๊ฐ€ ๋‘ ๊ฐœ ์„ ์–ธ๋˜์–ด ์žˆ๋Š” ๋‚˜์˜ controller๋ฅผ ๋งˆ์ฃผํ–ˆ๋‹ค;;;

 

๊ทธ๋ ‡๋‹ค๋ฉด, ์™œโธŒโ—ฆฬˆโƒโธสทสฐสธห€ฬฃห€ฬฃห€ฬฃ 2๊ฐœ๋ฅผ ์“ฐ์ง€ ๋ชปํ• ๊นŒ??

๊ตฌ๊ธ€๋ง์„ ์ข€ ํ•ด๋ณด๋‹ˆ ๊ธˆ์„ธ Stackoverflow์—์„œ๋„ ์˜ˆ์ „๋ถ€ํ„ฐ ๋‚˜์™”๋˜ ์ด์Šˆ๋ผ๋Š” ๊ฑธ ์•Œ๊ฒŒ๋˜์—ˆ๋‹ค. (๊ถ๊ธˆํ•œ ์‚ฌ๋žŒ์€ ์•„๋ž˜ ๋งํฌ GO!)

 

https://stackoverflow.com/questions/27189730/multiple-requestbody-values-in-one-controller-method

 

Multiple @RequestBody values in one controller method

I'm receiving error 400 when I send PATCH request to my endpoint that looks like this @RequestMapping(value = "...", method = RequestMethod.PATCH, consumes = "application/json", produc...

stackoverflow.com

 

 

๊ทธ๋ž˜์„œ ๊ฒฐ๋ก ์€ ๋ถˆํ–‰ํ•˜๊ฒŒ๋„ Web Application์˜ ๊ตฌ์กฐ์ƒ ์ด์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. @RequestBody๋Š” Single Object๋งŒ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์ฃ . ๊ทธ๋ž˜์„œ ์œ„์™€ ๊ฐ™์ด ์—ฌ๋Ÿฌ ๊ฐœ์˜ @RequestBody๋ฅผ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. ๋”ฐ๋ผ์„œ ์ถ”๊ฐ€๋˜๋Š” ์ •๋ณด๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‘ ๊ฐœ์˜ DTO๋ฅผ Single Object๋กœ ๊ตฌ์„ฑํ•˜์—ฌ Parameter setting์„ ํ•˜์˜€๋‹ค

 

๋