我正在使用@JsonProperty(name = "property_name")
(杰克逊)注释,只要json中的属性名称与对象中的属性名称不同。有没有办法可以通过编程方式在代码中的其他位置访问此信息?
示例:
public class Entity {
protected long entityName;
@JsonProperty("entity_name")
public long getEntityName() {
return entityName;
}
public void setEntityName(String entityName) {
this.entityName = entityName;
}
}
我需要的是将entity_name映射到entityName的方法。例如,getActualFieldName("entity_name")
应该返回"entityName"
。我可以保留一个包含所有这些映射的单独文件,但我不想这样做,因为此信息已经以@JsonProperty
注释的形式出现。如果我能以某种方式从那里提取它,它会简化一些事情。