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

DataBinder using constructor parameter should use path variables #22748

Closed
desmethans opened this issue Apr 5, 2019 · 1 comment
Closed

DataBinder using constructor parameter should use path variables #22748

desmethans opened this issue Apr 5, 2019 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@desmethans
Copy link

desmethans commented Apr 5, 2019

When the DataBinder uses setters it uses request parameters and path variables to fill the object. 😃

Given a class Customer:

class Customer {
  private int id;
  private String name;
    public void setId(int id) {	this.id = id;}
    public void setName(String name) {this.name = name;}
    @Override public String toString() {return id + ":" + name;}
}

and a class CustomerController:

@RestController
@RequestMapping("customers")
class CustomerController {
  @PostMapping("{id}")
  void create(Customer customer) {
    System.out.println(customer);
  }
}

when you do a POST request to localhost:8080/customers/1?name=rod, the Customer is nicely filled and 1:rod appears on the console.

When the DataBinder uses a parametrized constructor it does not use path variables. 😟

Given a class Supplier:

class Supplier {
  private final int id;
  private final String name;
  Supplier(int id, String name) {this.id = id; this.name = name;}
  @Override public String toString() {return id + ":" + name;}
  }
}

and a class SupplierController:

@RestController
@RequestMapping("suppliers")
class SupplierController {
  @PostMapping("{id}")
  void create(Supplier supplier) {
    System.out.println(supplier);
  }
}

when you do a POST request to localhost:8080/suppliers/1?name=rod, you get
java.lang.NoSuchMethodException: org.example.databinder.Supplier.<init>().

@jhoeller jhoeller self-assigned this Apr 5, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 5, 2019
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) labels Apr 7, 2019
@rstoyanchev rstoyanchev assigned rstoyanchev and unassigned jhoeller Jun 27, 2023
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 27, 2023
@rstoyanchev rstoyanchev added this to the 6.1.0-M2 milestone Jun 27, 2023
@rstoyanchev
Copy link
Contributor

This was covered by the changes for #26721, and in particular by ea398d7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants