I am developing a REST service within Wildfly 23.0.2.Final
. I have an EAR which contains an EJB and a WAR module. The WAR module is the JAX-RS service. Most of my entities leverage polymorphism, such as:
public class EchoResponse extends AjaxBody<Boolean> {
private static final long serialVersionUID = 4762378876367068194L;
/**
*
*/
public EchoResponse() {
super();
}
/**
* @param result
*/
public EchoResponse(Boolean result) {
super(result);
}
}
which extends
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "__type")
@JsonSubTypes({
@Type(value = EchoResponse.class, name = "EchoResponse"),
...
})
public class AjaxBody<T> implements Serializable {
private static final long serialVersionUID = 3528022080494570805L;
private T result;
public T getResult() {
return result;
}
public void setResult(T result) {
this.result = result;
}
public AjaxBody() {
}
public AjaxBody(T result) {
this.setResult(result);
}
}
However, polymorphism is not considered at all and in the responses I do not receive the __type
attribute, causing the client module (a Java web application built over Spring and deployed in a simple Tomcat instance) to error out while trying to unmarshall the response (both the service and the client share the same Java module where entities are defined).
I also noticed that all annotations are ignored, for example @JsonIgnore
.
I already checked my Jackson dependencies, and confirmed they are all in provided
scope. Also, I tried adding the jboss-deployment-structure.xml
as follows:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<ear-subdeployments-isolated>true</ear-subdeployments-isolated>
<sub-deployment name="scoofer-web.war">
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
One more note: all the endpoints support both application/json
and application/xml
: if invoked via XML, the attribute __type
is present in the body
node, as expected.
What am I still missing?
I've filed RESTEASY-2948 as this is not documented properly. To fix this you need to set the resteasy-prefer-jackson-over-jsonb
property. The simplest way is to use CLI to change the value in the subsystem:
/subsystem=jaxrs:write-attribute(name=resteasy-prefer-jackson-over-jsonb, value=true)
This should also not require you to include a jboss-deployment-structure.xml
. One thing to note though is this does affect all deployments.