users@jersey.java.net

[Jersey] Re: Missing maven dependency

From: Peter Tap <ptrtap_at_yahoo.com>
Date: Wed, 27 Jul 2011 17:54:21 -0700 (PDT)

Folks,

I generated a sample "Jersey + Grizzly2" app from the Maven archetype catalog at http://download.java.net/maven/2. It creates a simple class that produces "text/plain" output: I changed it a little to produce json output as shown below:


@Path("/myresource")
public class MyResource {
    @GET
    @Produces("application/json")
    public String getIt() {
        return "Got it!";
    }
}


I also ensured that dependency "jersey-json" is uncommented in pom.xml:

- <dependency>
 <     <groupId>com.sun.jersey</groupId>
 <    <artifactId>jersey-json</artifactId>
   <version>${jersey-version}</version>
</dependency>

When I run the application and browse from my browser, I see that it generates the string output as expected.

Now, I made a simple change. Instead of returning a single string, I am returning an array of strings:


    public String[] getIt() {
        String[] retVal = {"a", "b"};
        return retVal;   
    }


However, when I run the application with this change, I get the following exception:


SEVERE: Mapped exception to response: 500 (Internal Server Error)

javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException:
A message body writer for Java class [Ljava.lang.String;, and Java type class [Ljava.lang.String;, and MIME media type application/json was not found
.
How do I fix this problem?

Thank you in advance for your help.

Regards,
Peter