com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input

作者原创,转载请注明转载地址

第一次遇到该异常,在网上搜了很长时间也没找到解决答案,特此记录

1.异常展示:

com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
 at [Source: java.io.StringReader@11a92b24; line: 1, column: 1]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
    at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:2931)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2873)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
    at com.allcam.system.utils.JSonUtils.readValue(JSonUtils.java:30)
    at com.allcam.system.manager.statistics.impl.UserResourceDayStatisticsServiceImpl.getResourceDayStatistics(UserResourceDayStatisticsServiceImpl.java:45)
    at com.allcam.system.manager.statistics.impl.UserResourceDayStatisticsServiceImpl$$FastClassByCGLIB$$6b11b7f.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:710)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:643)
    at com.allcam.system.manager.statistics.impl.UserResourceDayStatisticsServiceImpl$$EnhancerByCGLIB$$65dd2f5a.getResourceDayStatistics(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy56.getResourceDayStatistics(Unknown Source)
    at com.allcam.system.manager.statistics.controller.UserResourceDayStatisticsController.getUserResourceDayStatistics(UserResourceDayStatisticsController.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)[2017-08-16 17:06:54,911][DEBUG][org.apache.http.impl.conn.Wire.wire(Wire.java:72)][http-nio-8080-exec-3] -  << "HTTP/1.1 200 OK[\r][\n]" -
[2017-08-16 17:06:54,912][DEBUG][org.apache.http.impl.conn.Wire.wire(Wire.java:72)][http-nio-8080-exec-3] -  << "Server: Apache-Coyote/1.1[\r][\n]" -

2.异常解析,本异常报错的原因为调用webservice服务,从webservice返回的对象没有将其转为json对象,而是直接将对象返回了,所以从webservice返回的时候

就报了此错误,

3.解决方案:将webservice返回的对象转化为json格式,,特此将原代码贴出:

  @ResponseBody
    @RequestMapping(value="resDayStatistics")
    public String getUserResourceDayStatistics(HttpServletRequest request,HttpServletResponse response){
        UserResourceDayStatistics dayStatistics2 = new UserResourceDayStatistics();
        try
        {
            UserResourceDayStatistics dayStatistics = new UserResourceDayStatistics();
            InputStream inputStream= request.getInputStream();
            String reqJson=IOUtils.toString(inputStream,ServiceContants.UTF8_CODE);
            if(reqJson != null && reqJson != ""){
                //json转成UserResourceDayStatistics对象
                dayStatistics=JSonUtils.readValue(reqJson, UserResourceDayStatistics.class);
            }
            
            dayStatistics2=dayService.getResourceDayStatistics(dayStatistics);
       
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       // return "/main/webapp/dayStatistics.jsp";
        return JSonUtils.toJSon(dayStatistics2);  //返回json格式对象
    }
}

由于要返回的是一个json对象,所以在方法头上加一个@ResponseBody注解,该注解的作用是将返回结果的格式写入到返回结果中,否则就会解析为一个页面。。。。。。

 

posted @ 2017-08-16 19:54  香吧香  阅读(57176)  评论(0编辑  收藏  举报