Jersey Json使用java.lang.NullPointerException进行映射,无法生成JSON

时间:2013-07-02 08:20:35

标签: java json rest maven jersey

我有一个带有@XMLRootElement注释的域类,它将从服务返回。

我的服务类似于:

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/GetProductList")
public Response getProductList(@QueryParam("Username") String username,
                             @QueryParam("Password") String password) {

        CategoryResponse result = new CategoryResponse(returnDummyCategories());

        return Response.ok().entity(result).build();
    } catch (Exception e) {
        log.error("Error fetching products.", e);
        throw new WebApplicationException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

此外,我已将init参数放在web.xml文件中:

<init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
     </init-param>

我也把代码

<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.17</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.17</version>
    </dependency>
<dependency>
  <groupId>com.owlike</groupId>
  <artifactId>genson</artifactId>
  <version>0.97</version>
</dependency>
pom.xml文件中的

但我仍然得到例外:

java.lang.NullPointerException
com.sun.jersey.spi.container.ContainerRequest.<init>(ContainerRequest.java:188)
com.sun.jersey.spi.container.servlet.WebComponent.createRequest(WebComponent.java:446)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:380)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
info.magnolia.cms.filters.ServletDispatchingFilter.doFilter(ServletDispatchingFilter.java:123)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.filters.CompositeFilter.doFilter(CompositeFilter.java:67)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.VirtualUriFilter.doFilter(VirtualUriFilter.java:70)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.module.cache.executor.Bypass.processCacheRequest(Bypass.java:58)
info.magnolia.module.cache.executor.CompositeExecutor.processCacheRequest(CompositeExecutor.java:66)
info.magnolia.module.cache.filter.CacheFilter.doFilter(CacheFilter.java:153)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:61)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.i18n.I18nContentSupportFilter.doFilter(I18nContentSupportFilter.java:76)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.RangeSupportFilter.doFilter(RangeSupportFilter.java:84)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.security.BaseSecurityFilter.doFilter(BaseSecurityFilter.java:60)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.security.SecurityCallbackFilter.doFilter(SecurityCallbackFilter.java:86)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:61)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.security.LogoutFilter.doFilter(LogoutFilter.java:93)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:61)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.module.templatingkit.filters.SiteMergeFilter.doFilter(SiteMergeFilter.java:97)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.MultiChannelFilter.doFilter(MultiChannelFilter.java:83)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:61)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.module.cache.filter.GZipFilter.doFilter(GZipFilter.java:75)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:61)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:85)
info.magnolia.cms.security.auth.login.LoginFilter.doFilter(LoginFilter.java:93)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.enterprise.registration.RegistrationFilter.doFilter(RegistrationFilter.java:52)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.UnicodeNormalizationFilter.doFilter(UnicodeNormalizationFilter.java:90)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.CosMultipartRequestFilter.doFilter(CosMultipartRequestFilter.java:91)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:61)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.module.devicedetection.filter.DeviceDetectionFilter.doFilter(DeviceDetectionFilter.java:73)
info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter.doFilter(OncePerRequestAbstractMgnlFilter.java:61)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.ContentTypeFilter.doFilter(ContentTypeFilter.java:102)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.ContextFilter.doFilter(ContextFilter.java:131)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.MgnlFilterChain.doFilter(MgnlFilterChain.java:83)
info.magnolia.cms.filters.CompositeFilter.doFilter(CompositeFilter.java:67)
info.magnolia.cms.filters.AbstractMgnlFilter.doFilter(AbstractMgnlFilter.java:91)
info.magnolia.cms.filters.SafeDestroyMgnlFilterWrapper.doFilter(SafeDestroyMgnlFilterWrapper.java:108)
info.magnolia.cms.filters.MgnlFilterDispatcher.doDispatch(MgnlFilterDispatcher.java:67)
info.magnolia.cms.filters.MgnlMainFilter.doFilter(MgnlMainFilter.java:108)
info.magnolia.cms.filters.MgnlMainFilter.doFilter(MgnlMainFilter.java:94)

找不到代码和配置的错误。

0 个答案:

没有答案