Reprint Please specify http://www.cnblogs.com/majianming/p/8491020.html
During the writing of the project, an issue was encountered that needed to define the format of the returned JSON field
For example, in an entity attribute, I have a field that is username, so the need to appear in JSON is user_name, that is, using the underscore name method
You can then use @JsonProperty this annotation to customize the @JsonProperty ("user_name")
But if all my attributes are to be used in this way, do I add one by one?
In fact, just define Jackson's property naming policy to add
(yml format)
Spring
Jackson
Property-naming-strategy:snake_case
(propreties format)
Spring.jackson.property-naming-strategy=snake_case
You can do it.
All policies are
Strategy |
Example |
Note |
Lower_camel_case |
UserName |
Default Policy |
Kebab_case |
User-name |
|
Lower_case |
Username |
|
Snake_case |
User_name |
|
Upper_camel_case |
UserName |
|
There seems to be no problem here, but if I have only one entity, the attribute name needs to be mapped to one of the above conditions,
But there are many attribute names, too lazy to add it?
In fact, there are methods, as long as the need to add the entity@JsonNaming
(PropertyNamingStrategy.SnakeCaseStrategy.
class
)这样的注解就可以了
The strategies you can use here are also consistent with those in the table above
Above
Reference
Http://www.baeldung.com/jackson-advanced-annotations
- https://stackoverflow.com/a/40730352
Reprint Please specify http://www.cnblogs.com/majianming/p/8491020.html
sping boot returns the JSON format definition