Reputation: 11966
I'm trying to use JAXB annotations with RestEasy in order to choose names and elements order in my JSON output.
Somehow, it isn't working, even if the RestEasy doc says it's possible.
Here some code:
@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;
}*/
}
And here an example output:
{
"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
}]
}
The JAXB annotations don't seem to be taken in account at all.
Any idea will be considered...
Upvotes: 2
Views: 2872
Reputation: 36
If you are using JBoss (or WildFly as it's now called) as an application server, you may be experiencing RestEasy using the Jackson (http://jackson.codehaus.org/) JSON marshaller, which has its own annotations – you can find the documentation linked from Jackson's homepage. They are a bit more expressive than "just" JAXB, you may want to consider them if you specifically target JSON output only.
If you would rather only use JAXB, as you example indicates, you can switch from Jackson to something different by specifying which resteasy provider module you want to use in a jboss-deployment-structure.xml
, as detailed in this answer.
Upvotes: 2