I am trying to make a generic REST api using Jersey and I followed the following blog for this: https://theza.ch/2009/08/11/uri-extensions-in-jersey/
So what is happening is that the server is working fine when I use .xml in my url and when I use .json, it gives a 500 Internal Server error. I have tried different things,but to no avail. Could anyone by any change know why this is happening in json and not for xml and how to fix this?
My code looks something like this:
@GET
@Path("/order/{product-key}/getorderid")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getOrderIdByDomain(@Context HttpServletRequest request,
@PathParam("product-key") final String productKey,
@QueryParam("domain-name") final String domainName ) throws Exception
{
try
{
Integer response = doSomething();
return Response.status(200).entity(response).build();
}
catch (Exception lbe)
{
Hashtable response = new Hashtable();
response.put("Error",lbe.getMessage());
return Response.status(400).entity(response).build();
}
}
UPDATE:
After adding the jersey-json dependency, the 500 error changed to 200 OK but I am still getting an empty response. For xml, I am getting the expected response. Did someone face a similar issue? Please suggest something because I have tried a few things from other answers but it doesn't seem to be working.
StackTrace:
Caused by: java.lang.AbstractMethodError
at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findSerializer(AnnotationIntrospector.java:1148)
at org.codehaus.jackson.map.ser.BasicSerializerFactory.findSerializerFromAnnotation(BasicSerializerFactory.java:362)
at org.codehaus.jackson.map.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:252)
at org.codehaus.jackson.map.ser.StdSerializerProvider._createUntypedSerializer(StdSerializerProvider.java:782)
at org.codehaus.jackson.map.ser.StdSerializerProvider._createAndCacheUntypedSerializer(StdSerializerProvider.java:735)
at org.codehaus.jackson.map.ser.StdSerializerProvider.findValueSerializer(StdSerializerProvider.java:344)
at org.codehaus.jackson.map.ser.StdSerializerProvider.findTypedValueSerializer(StdSerializerProvider.java:420)
at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:601)
at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:256)
at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1606)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:520)
at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.writeTo(JacksonProviderProxy.java:160)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
... 48 more
I am using the following dependencies: jersey-server, jersey-json version 1.8.