在我dropwizard項目中,我有bean類,這是在資源類中使用這樣的命名策略:默認屬性在dropwizard
@GET
@Path("/{id}")
public Response getUser(@PathParam("id") Long id) {
return Response.ok(userDAO.get(id)).build();
}
class User {
private String id;
@JsonProperty("first_name")
private String firstName;
@JsonProperty("last_name")
private String lastName;
}
有沒有辦法,我可以添加一個方法來dropwizard配置中的應用類告訴javax使用snake_case命名策略將我的bean實體(用戶)映射到json。這將幫助我避免爲每個類的成員使用@JsonProperty(「first_name」)註釋。
在沒有上述標註的,我的JSON是這樣的:
{
"firstName": "John",
"lastName": "Doe"
}
I would rather like it to be :
{
"first_name": "John",
"last_name": "Doe"
}