Using resteasy-jackson2-provider instead of resteasy-jackson-provider
mattias_g Mar 5, 2014 11:26 AMHello.
I have am trying to use the newer com.fasterxml.jackson api instead of the old org.codehaus api without having to package jackson with the war file..
I found the several discussions on the developer mailing list ([wildfly-dev] Configurable implicit module imports, [wildfly-dev] Jackson 1 and 2 coexistence ) and as I understand it I am supposed to use the jboss-deployment-structure.xml to exclude the old provider and then specify org.jboss.resteasy.resteasy-jackson2-provider as a module dependency.
Right now my jboss-deployment-structure.xml looks like this.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jackson2-provider"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
And my code looks like:
@ApplicationPath("/v1")
public class App extends Application { }
@Path("foo")
public class FooController {
@Produces("application/json")
@GET
public RestResponse<String> get() {
System.out.println("HERE 1");
return new SuccessfulRestResponse<>("Foo Bar");
}
}
@Provider
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unused")
public class JacksonConfig implements ContextResolver<ObjectMapper> {
private static final Logger log = Logger.getLogger(JacksonConfig.class.getName());
@Override
public ObjectMapper getContext(final Class<?> type) {
final ObjectMapper mapper = new ObjectMapper();
System.out.println("******************************************* ");
log.info("Configured Jackson Json module");
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
return mapper;
}
}
public class RestResponse<T> {
private final String message;
private final T data;
private final boolean isSuccessful;
@JsonProperty("api_status")
private final ApiStatusCode apiStatusCode;
public RestResponse(T data, boolean isSuccessful, final ApiStatusCode apiStatusCode, final String message) {
this.data = data;
this.isSuccessful = isSuccessful;
this.apiStatusCode = apiStatusCode;
this.message = message;
}
// Getters/Setters removed
I also have a bean.xml in the project so the @Provider annotation should work.
When I try to call /foo I get a "Could not find MessageBodyWriter for response object of type: [snip].SuccessfulRestResponse of media type: application/json", the JacksonConfig provider never gets called.
If I exclude org.jboss.resteasy.resteasy-jackson2-provider and add com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider jar file to my war file then everything works as it should and JacksonConfig gets called.
The org.jboss.resteasy.resteasy-jackson2-provider exists in wildflys module directory.
Can anyone tell med what I am doing wrong?
[Edit]
I think I found part of the answer.
Chapter 21. JSON Support via Jackson
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
</exclusions>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
JacksonConfig now gets called as it should but now I get another exception:
2014-03-05 16:45:50,763 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to foo: java.lang.NoSuchMethodError: org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider._configForWriting(Lcom/fasterxml/jackson/databind/ObjectMapper;[Ljava/lang/annotation/Annotation;)Lcom/fasterxml/jackson/jaxrs/json/JsonEndpointConfig;
at org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider.writeTo(ResteasyJackson2Provider.java:137) [resteasy-jackson2-provider-3.0.6.Final.jar:]
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:129) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.interception.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:62) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:118) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.security.doseta.DigitalSigningInterceptor.aroundWriteTo(DigitalSigningInterceptor.java:143) [resteasy-crypto-3.0.6.Final.jar:]
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:122) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:99) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:427) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.6.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
Message was edited by: Mattias Gyllsdorff.
[Edit 2]
Resteasy Jackson 2 error in Wildfly 8 Final
Apparently this last exceptions is a bug with jackson 2.3.0. I will either have to upgrade the provided jackson to 2.3.2 or downgrade it to 2.2.3.
Message was edited by: Mattias Gyllsdorff. I am apparently not allowed to post a reply so I will have to use edit instead.