Bug with JAX-RS annotation processing
faeem.ali Sep 18, 2013 8:31 PMHey All ...
I suspect I've found a bug in Jboss AS 7.1.1 Final regarding JAX annotation processing for JSON. I've included a tiny project to this post that can be imported into eclipse (Juno) that shows the issue. Basically, JAX-RS seems to ignore @XmlElement annotations when the @Produces(MediaType.APPLICATION_JSON) is used. Please see the code below as an example:
<code>
@Path("/")
public class Test {
@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON) //this doesn't read the @XmlElement annotation
//@Produces(MediaType.APPLICATION_XML) //this works
public Msg getMsg() {
return new Msg();
}
}
</code>
<code>
@XmlRootElement
public class Msg implements Serializable {
private static final long serialVersionUID = 1L;
private String content = "Hello World";
public Msg() {
}
@XmlElement(name = "blah")
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
</code>
Output:
When using MediaType.APPLICATION_JSON:
{"content":"Hello World"}
When using MediaType.APPLICATION_XML
<msg>
</msg>
As the output shows, the @XmlElement annotation is not being processed, or not being processed correctly when JSON output is requested.
Also, if no @XmlElement is used, variable names are still mapped to XML/JSON provided the getters/setters exist. This may be a misunderstanding on my part, but I thought only variables explicitly marked with @XmlElement will be mapped to XML/JSON. This is not shown in the example above.
I'm using JBoss AS 7.1.1 in standalone mode. The only changes I've made to the configuration are adding a security domain and a database adaptor. The default RESTEasy configuration has not been modified in any way.
Please either point out my mistake or confirm this as a bug. If it's the latter, I'll post a bug report.
Faeem
-
TestRestEasy.tar.gz 3.1 KB