aw! I'm actually wrong! List<String> probably is not supported..
List<XmlRootElementAnnotatedClass> and application/xml or
application/json; best way would be look at our entity types test, which
can be found here:
http://java.net/projects/jersey/sources/svn/content/trunk/jersey/jersey-tests/src/test/java/com/sun/jersey/impl/entity/EntityTypesTest.java?rev=5211
sorry for initial misleading answer!
Pavel
On 7/28/11 5:49 PM, Pavel Bucek wrote:
> its because you are not really producing application/json (and jersey
> does not provide messagebodywriter for mediaType application/json and
> type String
>
> try this:
>
> @Path("/myresource")
> public class MyResource {
> @GET
> @Produces("text/plain")
> public String getIt() {
> return "Got it!";
> }
> }
>
> see jersey user guide for more info support about json:
> http://jersey.java.net/nonav/documentation/latest/json.html or related
> samples (json-from-jaxb, jsonp, ..)
>
> Regards,
> Pavel
>
> On 7/28/11 5:41 PM, Peter Tap wrote:
>> Pavel,
>>
>> Thank you for your help.
>>
>> Changing the return type from String[] to List<String> does not get
>> rid of the error. The error message is slightly different:
>>
>> 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 java.util.ArrayList, and Java
>> type java.util.List<java.lang.String>, and MIME media type
>> application/json was not found
>>
>> There must be something that I am missing fundamentally. I also
>> ensured that dependency "jersey-json" is present in pom.xml: Is there
>> anything else that I have overlooked?
>>
>> Appreciate your help.
>>
>> Regards,
>> Peter
>> -----------------
>>
>> JAX-RS don't support String[] afaik, you would need to write your own
>> MessageBodyReader/Writer. But there is much easier solution: return
>> List<String> instead.
>>
>> Regards,
>> Pavel
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>> *From:* Peter Tap <ptrtap_at_yahoo.com>
>> *To:* "users_at_jersey.java.net" <users_at_jersey.java.net>
>> *Sent:* Wednesday, July 27, 2011 5:54 PM
>> *Subject:* Re: Missing maven dependency
>>
>> 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
>>
>>
>