users@jersey.java.net

[Jersey] Re: Error returning string list in Web service method

From: Peter Tap <ptrtap_at_yahoo.com>
Date: Thu, 28 Jul 2011 16:17:02 -0700 (PDT)

After some experimentation, here is what I have found out. Perhaps others may find it useful.


If you define array, list, or collection as the return value, it does not work:

    @GET
    @Produces("application/json")

      public String[] getIt() {   // THIS DOES NOT WORK

        ...
      }

However, if you wrap your collection in another class, it works:

   @XmlRootElement
   public class MyItem {
       public String[] items;
   }

    @GET
    @Produces("application/json")

      public MyItem getIt() {   // THIS WORKS

        ...
      }


This seems to be a limitation in Jersey's implementation. A similar web service under Windows (WCF) does not have an issue returning String[] from a web service method.

Regards,
Peter