Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@JsonProperty annotation seems to be ignored when using query object parameter #39833

Closed
jianjianghui opened this issue Mar 5, 2024 · 1 comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid

Comments

@jianjianghui
Copy link

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 5, 2024
@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2024
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants