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

Provide a way to customize the names of JavaBean properties when they're read and written for data binding purposes [SPR-9242] #13880

Closed
spring-projects-issues opened this issue Mar 14, 2012 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) 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

spring-projects-issues commented Mar 14, 2012

Keith Donald opened SPR-9242 and commented

It's becoming more and more common in a HTTP environment for REST APIs to define fields using underscore notation e.g. (access_token) vs. camelCase notation (e.g. accessToken). Facebook and Twitter APIs, for example, use underscores throughout their field names for space separators and do not use camel case except in a few legacy compatibility scenarios.

I am interested in being consistent with what the others are doing--for this reason I prefer underscore_naming for my public REST API that can be accessed by different clients written in different languages. Unfortunately, Spring's data binding framework doesn't AFIK provide a feature where a custom bind field name e.g (POST resource?access_token=?) can be mapped onto a bean property (e.g. Resource#get/setAccessToken(...)). Defining properties like getAccess_token() is less than ideal since it doesn't match local Java coding conventions.

Jackson has a @JsonProperty annotation that provides such a feature for JSON reading and writing, but this doesn't cover the POST form parameter binding case. We could provide something similar e.g. @Property. Alternatively, we could just support mapping underscore style naming onto camelCase naming.

Another environment where this could be helpful would be in the use of Postgres databases. Postgres column names are case insensitive by default so underscore is by far the most common convention there.


Affects: 3.1.1

Issue Links:

1 votes, 2 watchers

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Here is a reference to another variation on the same requirement, this time trying to bind short query parameter names onto longer command object property names.

I'm marking this also as SpringWEB as well since @InitBinder methods may be a good place for enabling such customizations per command object (or globally via WebBindingInitializer). Certainly the underscore-to-camelback feels like something that should be specified once.

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Maybe our support for setting Jackson PropertyNamingStrategy (especially with the LowerCaseWithUnderscoresStrategy one) address the need describe in this issue ?

@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) in: web Issues in web modules (web, webmvc, webflux, websocket) 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) in: web Issues in web modules (web, webmvc, webflux, websocket) 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