我正在尝试将 JAXB 注释与 RestEasy 一起使用,以便在我的 JSON 输出中选择名称和元素顺序。
不知何故,它不起作用,即使 RestEasy 文档说它是可能的。
这里有一些代码:
@XmlRootElement(name = "translation")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "translation", propOrder = {
"key",
"value"
})
public class TranslationDTO {
public TranslationDTO() {}
public TranslationDTO(Translation translation) {
setKey(translation.getTranslationKey().getValue());
setValue(translation.getContent());
//setCreationDate(translation.getCreatedTimestamp());
}
@XmlElement(name = "key")
private String key;
@XmlElement(name = "value")
private String value;
//private Date creationDate;
@XmlElement(name = "key")
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@XmlElement(name = "value")
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
/*@XmlElement(name = "creationDate")
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}*/
}
这里是一个示例输出:
{
"name":"i18nhelp",
"currentVersion":"1",
"currentTotalKeys":28,
"oldTotalKeys":0,
"totalLanguages":2,
"languageDtos":[{
"name":"Anglais",
"iso639":"en",
"totalCurTrans":28,
"newCurTrans":28,
"oldTrans":0
},
{
"name":"Français",
"iso639":"fr",
"totalCurTrans":28,
"newCurTrans":28,
"oldTrans":0
}]
}
似乎根本没有考虑 JAXB 注释。
任何想法都会被考虑...