【发布时间】:2015-09-19 17:29:01
【问题描述】:
在我的 dropwizard 项目中,我有 bean 类,它们在 Resource 类中使用,如下所示:
@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"
}
【问题讨论】:
标签: java json dropwizard