0

This is a slight variation to the question here. I'm not using Maven but have the jersey-bundle-1.17.1 included in the classpath. It seems to include all the classes in jersey-json. However I also added jersey-json to classpath and WEB-INF/lib and get the same error. I'm POSTing json

{ to: 'John', company: 'Costo' }

Anything obvious?

Recipient is simple POJO with two string fields - to and company

@POST
@Path("/saveit")
@Consumes(MediaType.APPLICATION_JSON )
@Produces( MediaType.APPLICATION_JSON )
public Response saveit(Recipient rec) {
         System.out.println(rec); 
         ....
}

But I still get the error:

Apr 20, 2014 8:17:23 PM com.sun.jersey.spi.container.ContainerRequest getEntity    
SEVERE: A message body reader for Java class com.company.guestbook.model.Recipient, and Java type class com.company.guestbook.model.Recipient, and MIME media type application/json was not found.
    The registered message body readers compatible with the MIME media type are:
    application/json ->
      com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
      com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
      com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
    */* ->
      com.sun.jersey.core.impl.provider.entity.FormProvider
      ...
Community
  • 1
  • 1
Fakeer
  • 985
  • 1
  • 13
  • 29

1 Answers1

0

This should fail at compile time since your method implementation has no return object (i.e., it's a void return) but the method signature indicates that a Response object is returned. Your implementation simply prints the Recipient object to standard output (which is likely to end up in your container's log file).

I see you're not using Maven to manage your dependencies (which is fine) but have you added the Jersey required dependencies? For example, this error report looks similar to yours...

Community
  • 1
  • 1
Jan Nielsen
  • 10,892
  • 14
  • 65
  • 119
  • thanks. just added the missing ellipsis. avoiding cluttering with the irrelevant parts. the exception occures during the marshalling so we never get to the sysout. – Fakeer Apr 21 '14 at 03:58
  • @Fakeer - it's a lot easier to help you if you include the relevant code. Please do strip-down the example to the simplest proof-of-concept which shows the error you're encountering; otherwise, we are left guessing what the code might look like which triggers the error. And do also include the whole error... – Jan Nielsen Apr 21 '14 at 21:16