Description
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:
- Customizable parameter name when binding an object [SPR-10183] #14816 Customizable parameter name when binding an object
- Support for form submissions with field names that follow JavaScript object notation [SPR-9244] #13882 Support for form submissions with field names that follow JavaScript object notation
- Add @FormAttribute attributes to customize x-www-form-urlencoded [SPR-13433] #18012 Add
@FormAttribute
attributes to customize x-www-form-urlencoded
1 votes, 2 watchers