Skip to content

Add support for custom x-www-form-urlencoded payload field names mapping #3890

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

Closed
Smedzlatko opened this issue Sep 3, 2015 · 5 comments
Closed
Labels
status: invalid An issue that we don't feel is valid

Comments

@Smedzlatko
Copy link

When processing an HttpRequest with x-www-form-urlencoded content, we can use a controller with POJO matching the payload structure.

Example payload: value_first=value1&value_second=value2

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
 public String handlePost(@ModelAttribute Body body) {
 }

POJO:

public class Body {
 private String value_first;
 private String value_second;
}

The problem is that the variable names must match the field names in the HttpRequest payload in order to be processed by the controller. There is not way of naming them differently, for example, if I do not want to use underscopes in Java variable and method names.

What I would appreciate would be using something like this:

@FormAttribute
private String value1;
@philwebb philwebb changed the title Add support for custom x-www-form-urlencoded pyalod field names mapping Add support for custom x-www-form-urlencoded payload field names mapping Sep 4, 2015
@philwebb
Copy link
Member

philwebb commented Sep 4, 2015

Changes would need to be made in core Spring to support this. I've raised SPR-13433 for them to consider it. Feel free to track that issue.

Thanks for the suggestion.

@philwebb philwebb added the status: invalid An issue that we don't feel is valid label Sep 4, 2015
@philwebb philwebb closed this as completed Sep 4, 2015
@philwebb
Copy link
Member

@Smedzlatko Rossen has some followup questions if you could comment on SPR-13433

@Smedzlatko
Copy link
Author

@philwebb As for the Rossens' comment: yes, I should have clarified this in my simplified example. It should , of course, be:

@FormAttribute("value_first")
private String value1;

As for the requirement, I am not saying that this is a core functionality of Spring that I am desperately missing but imagine this scenario:

You are processing a form-encoded payload from a third party service and you want to use POJO to map the values. You use camelCase in your whole project and now you are forced to use underscopes if the third party service does so (in the POJO) or write your own converter just for this purpose.

When I encountered this problem, I immediately looked for some Spring functionality to tackle this and was suprised that there is none. Feel free to close this issue if you feel that I am being unreasonable but I expected more people having this issue as well.

@wilkinsona
Copy link
Member

@Smedzlatko Could you make that comment on SPR-13433, please? I'd copy it over but I think it would be better if it's obviously from you.

@Smedzlatko
Copy link
Author

@wilkinsona I have created an account there and copied my reply. Thank you for you support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants