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

Combine @PathParam with @RequestBody [SPR-14149] #18721

Closed
spring-projects-issues opened this issue Apr 12, 2016 · 2 comments
Closed

Combine @PathParam with @RequestBody [SPR-14149] #18721

spring-projects-issues opened this issue Apr 12, 2016 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

Suresh opened SPR-14149 and commented

xpI am using spring boot as RESTFul service. I have a requirement to combine @PathParam value with @RequestBody POJO.

The reason is, I am using hibernate validator to validate the POJO. I can manually merge @PathParam values in Controller class but the hibernate validator is called before the merge happens.

*Example:
I have a POJO as defined below.

public Class User{
  private String id;
  private String name;
  private String firstName;
....
}

Resource class as defined below:

@RestController
@RequestMapping(value = "user")
public Class UserResource{

  @RequestMapping(value = "{id}", method = RequestMethod.PUT)
  public String update(@PathVariable String id, @RequestBody @Validated(UpdateValidator.class) User user){
    user.setId(id);// Have to avoid this.
    service.update(user);
  }
}

No further details from SPR-14149

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

I don't see a clear cut solution for this in the general case, overlaying the de-serialized request body with path variables. It's bound to lead to surprises. It seems to me however that the the UpdateValidator should be in sync with the expected input. In other words either expect the id to be in the body or don't validate it. Beyond that it's not very hard to create a custom argument resolver that combines the behaviors. As I said I just don't see that working out more generally.

@spring-projects-issues
Copy link
Collaborator Author

Suresh commented

Thank you for the response. I am going with id value in POJO and validating using hibernate validator.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
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) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants