Closed talentedasian closed 3 years ago
Would you mind taking a step back and describing the actual problem to be solved?
The image above is the desired output. Even though the field is named politicalParty
, a @JsonProperty
annotation is present with the value of political_party
. This should be the default behavior for names of Hal+Form _templates property name value(_templates.default.properties[0].name
) because the @JsonProperty
values are the one that are expected in the @RequestBody
.
For example, I have a DTO that is used in a @RequestBody
:
public class AddPoliticianDTORequest {
@JsonProperty("first_name")
String firstName;
@JsonProperty("last_name")
String lastName;
Spring MVC expects the body of the POST method to have json values of first_name and last_name. If I were to make an affordance for this in a Hal+Form mediatype, the resulting data would be:
"templates":{
"default":{
"method":"post",
"properties":[
{
"name":"firstName",
.......
},
{
"name":"lastName",
.......
}
],
"target":"http://localhost:8080/api/politician/politicians"
}
}
The response would ultimately break your clients that use your api since you expect first_name and last_name instead of "firstName" and "lastName" all because of the @JsonProperty. The name of the property values should always be the value of a @JsonProperty annotation when it is present and if not, use the default field name.
Awesome, thanks for the additional context.
Make the default name or value of the field
name
of theDefaultMetadataProperty
to the value that is present in the @JsonProperty annotation else, use the default field name.