glassfish
  1. glassfish
  2. GLASSFISH-20576

Internal Server Error on JSON REST web service returning array

    Details

    • Type: Bug Bug
    • Status: In Progress
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 4.0_b89_RC5
    • Fix Version/s: 4.1
    • Component/s: jax-rs
    • Labels:
      None
    • Environment:

      glassfish-4.0-b90-05_22_2013, jdk1.7

      Description

      The following REST web service causes internal server error (and no stack trace in server.log). Returning an empty array works, but as soon as there are elements in the array - it does not.

      @GET
      @Produces("application/json")
      public Object[] getArray() {
      return new Object[]

      {"Test"}

      ;
      }

        Activity

        Hide
        Marek Potociar added a comment -

        Targeting for GF 4.0.1, Re-assigning to dev eng. for evaluation.

        Show
        Marek Potociar added a comment - Targeting for GF 4.0.1, Re-assigning to dev eng. for evaluation.
        Hide
        Michal Gajdos added a comment -

        Which Json provider from Jersey are you using? Have you configured one? Thanks.

        Show
        Michal Gajdos added a comment - Which Json provider from Jersey are you using? Have you configured one? Thanks.
        Hide
        Peter Salomonsen added a comment -

        I haven't configured anything - no web.xml at all. Just application config class like this:

        @javax.ws.rs.ApplicationPath("webresources")
        public class ApplicationConfig extends Application {

        }

        And the REST service class:

        @Path("generic")
        public class GenericResource {

        @Context
        private UriInfo context;

        public GenericResource() {
        }

        @GET
        @Produces("application/json")
        public Object[] getArray() {
        return new Object[]

        {"Test"}

        ;
        }
        }

        That's all.

        Show
        Peter Salomonsen added a comment - I haven't configured anything - no web.xml at all. Just application config class like this: @javax.ws.rs.ApplicationPath("webresources") public class ApplicationConfig extends Application { } And the REST service class: @Path("generic") public class GenericResource { @Context private UriInfo context; public GenericResource() { } @GET @Produces("application/json") public Object[] getArray() { return new Object[] {"Test"} ; } } That's all.
        Hide
        Michal Gajdos added a comment -

        The easiest way would be registering JacksonFeature (make sure you have jersey-media-json-jackson on your classpath) in your ApplicationConfig. Something like:

        public Set<Class<?>> getClasses() {
            return new HashSet<Class<?>>() {{ add(GenericResource.class); add(JacksonFeature.class); }};
        }
        
        Show
        Michal Gajdos added a comment - The easiest way would be registering JacksonFeature (make sure you have jersey-media-json-jackson on your classpath) in your ApplicationConfig . Something like: public Set< Class <?>> getClasses() { return new HashSet< Class <?>>() {{ add(GenericResource.class); add(JacksonFeature.class); }}; }
        Hide
        Peter Salomonsen added a comment -

        org.glassfish.jersey.jackson.JacksonFeature works as you propose. MoxyJsonFeature gives the server error, and JettisonFeature says it cannot find a MessageBodyWriter. Is MoxyJsonFeature the default? Shouldn't this also be able to handle arrays?

        Show
        Peter Salomonsen added a comment - org.glassfish.jersey.jackson.JacksonFeature works as you propose. MoxyJsonFeature gives the server error, and JettisonFeature says it cannot find a MessageBodyWriter. Is MoxyJsonFeature the default? Shouldn't this also be able to handle arrays?

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            Peter Salomonsen
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: