Linked Questions

Popular Questions

Unable to Send Json Response with Jersey Maven Rest Services

Asked by At

I'm working on a project where I need to write web-services in Java Jersey framework. Everything is working if I run web-services using IntelliJ. But If I make jar of my java program and run it using the cmd. My web-services throws exception when sending back Json Response.

Below is Exception.

AM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo SEVERE: MessageBodyWriter not found for media type=application/json, type=class response.BaseResponse, genericType=class response.BaseResponse.

I added the Jersey media json dependency in pom.file also.

<dependency>
   <groupId>org.glassfish.jersey.media</groupId>
   <artifactId>jersey-media-json-jackson</artifactId>
   <version>2.26</version>
</dependency>

And below is BaseResponse class for Json response.

@XmlRootElement
public class BaseResponse {

    public static final int SUCCESS = 1;
    public static final int FAILURE = 0;

    private int status;
    private String message;

    BaseResponse() {
    }

    public BaseResponse(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "BaseResponse{" +
                "status=" + status +
                ", message='" + message + '\'' +
                '}';
    }
}

Also one thing more that I create the jar file using the maven-shade-plugin which creates a fat uber jar.

Related Questions