springboot version: 3.2.2,2.7.13
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/coupon")
public class CouponController {
@PostMapping
public String post(@RequestBody CouponReq couponReq) {
return "mallId:" + couponReq.getMallId();
}
@GetMapping
public String get(CouponReq couponReq) {
return "mallId:" + couponReq.getMallId();
}
}
import com.fasterxml.jackson.annotation.JsonProperty;
public class CouponReq {
@JsonProperty("mall_id")
String mallId;
public CouponReq() {
}
public String getMallId() {
return this.mallId;
}
@JsonProperty("mall_id")
public void setMallId(String mallId) {
this.mallId = mallId;
}
}
result
POST http://localhost:8080/api/coupon
Content-Type: application/json
{
"mall_id": "21343124"
}
# response: mallId:21343124
GET http://localhost:8080/api/coupon?mall_id=1234123
# response: mallId:null
Is this a bug, or am I doing something wrong?
Comment From: wilkinsona
You're doing something wrong. There's no JSON involved when you're providing the id as a query parameter so @JsonProperty has no effect.
If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.