0
鉴于与杰克逊注解的实体(模型)类,用于设置列名:如何获取所有Jackson/JAXB注释的属性值?
public class GridRowModel {
private Long maxRegulatedValue;
@JsonProperty(value="Max Regulated Value")
public Long getMaxRegulatedValue() {
return maxRegulatedValue;
}
@JsonProperty(value="Fares")
public Map<String, FareModel> getFares() {
return fares;
}
...
(可替代已经使用JAXB注解 - 例如@XmlElement(名称= “最大调节值”)
我需要一个getGridColumns
方法将返回一个JSON结构,从这个模型+其子模型提取的所有列名(所以这里将返回“最大规定值”,并从FareModel
所有@JsonProperty
值。)
问题是如何最好地解决这个问题?已经使用反射进行了讨论,例如像method.getAnnotation(JsonProperty.class).value())
,但不知道这是否会起作用,看起来并不理想。首先,它不会遵守@JsonPropertyOrder
(或JAXB中的propOrder
)指定的顺序。我想知道如果有一个更聪明的方式(?也许使用某种适配器)