【发布时间】:2016-07-19 14:07:34
【问题描述】:
我需要创建一个@JsonProperty 值到原始字段名称的映射。
可以实现吗?
我的 POJO 类:
public class Contact
{
@JsonProperty( "first_name" )
@JsonView( ContactViews.CommonFields.class )
private String firstName;
@JsonProperty( "last_name" )
@JsonView( ContactViews.CommonFields.class )
private String lastName;
public String getFirstName()
{
return firstName;
}
public void setFirstName( String firstName )
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName( String lastName )
{
this.lastName = lastName;
}
}
我需要这样的地图:
{"first_name":"firstName","last_name":"lastName"}
在此先感谢...
【问题讨论】:
-
您希望能够将 jsonProperty 值映射到字段名称值,对吗?
-
@dambros:是的。 JsonProperty 到 FieldNames 的映射
标签: java spring jackson objectmapper