Site icon NgDeveloper

4 reasons for @RequestBody null issue in Spring Boot

1. Make sure you have first letter as lowercase in all your json request & keys

This is specific to java POJO behaviours only.

Invalid JSON Request:

{
 "CouponId":18,
 "StoreName":"Flipkart",
 "ValidToday":true
}

Valid JSON Request:

{
 "couponId":18,
 "storeName":"Flipkart",
 "validToday":true
}

2. Make sure to import right RequestBody

If you are using Swagger then RequestBody might get imported from Swagger package, so check that and make sure to import RequestBody from here only,

Invalid RequestBody Import

some import from your swagger you can see in your controller.

Valid RequestBody Import:

import org.springframework.web.bind.annotation.RequestBody

3. Make sure you have getters / setters in your RequestBody class

yes this is must.

4. Make sure lombok installation is correct, if you are using lombok

Also make sure you have @Data or @Getter & @Setter in your Request Body class.

Exit mobile version