I am using Jersey to marshall a Java object to JSON, as follows:
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
@POST
@Consumes({MediaType.APPLICATION_JSON})
@Path("/test")
public Response replay(String input) throws IOException {
return Response.ok().entity(new MyClass()).build();
}
Am receiving the following exception:
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.company.MyClass, and Java type class com.company.MyClass, and MIME media type application/octet-stream was not found.
I understand that the solution here is to :
- Add the
jackson-jaxrs-json-provider
dependency - Use
com.sun.jersey.api.json.POJOMappingFeature
POJOMappingFeature
is normally configured in web.xml
.
Is there an alternative for applications which are annotation driven and do not use web.xml
?
Thanks