Reputation: 5110
I develop REST-service with undertow+resteasy+ajckson, when I run this with IDEA, everything is OK, but when I create "fat-jar" with gradle or maven I get error during GET query:
org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:67) at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:448) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:397) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:200) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
I could create jar without error with gradle build
and debug my service in IDEA.
My gradle file:
apply plugin: 'application'
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'example.json.RestServer'
jar {
manifest {
attributes 'Implementation-Title': 'Rest-server',
'Implementation-Version': '0.1',
'Main-Class': 'example.json.RestServer'
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
repositories {
jcenter()
}
dependencies {
compile 'io.undertow:undertow-core:1.4.0.Final'
compile 'io.undertow:undertow-servlet:1.4.0.Final'
compile 'org.jboss.resteasy:jaxrs-api:3.0.12.Final'
compile 'org.jboss.resteasy:resteasy-undertow:3.0.12.Final'
compile 'org.jboss.resteasy:resteasy-jackson-provider:3.0.12.Final'
testCompile 'junit:junit:4.12'
}
My source:
@Path("calculator")
public class Calculator {
@GET
@Path("squareRoot")
@Produces(MediaType.APPLICATION_JSON)
public Response squareRoot(@QueryParam("input") double input){
Result result = new Result("Square Root");
result.setInput(input);
result.setOutput(Math.sqrt(result.getInput()));
return Response.status(200).entity(result).build();
}
Upvotes: 1
Views: 1949
Reputation: 3507
Try to change your last code spinet like below because The anonymous GenericEntity subclass is required to supply the correct type information (otherwise erased by the compiler) for the writer.
@Path("calculator")
public class Calculator {
@GET
@Path("squareRoot")
@Produces(MediaType.APPLICATION_JSON)
public Response squareRoot(@QueryParam("input") double input){
Result result = new Result("Square Root");
result.setInput(input);
result.setOutput(Math.sqrt(result.getInput()));
return Response.ok(
new GenericEntity<Result >(result)
)
}
more explanation is here JAX-RS NoMessageBodyWriterFoundFailure
Upvotes: 0