• 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[ ][ ]" -
    [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[ ][ ]" -

    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注解,该注解的作用是将返回结果的格式写入到返回结果中,否则就会解析为一个页面。。。。。。

  • 相关阅读:
    Spark&Hadoop:scala编写spark任务jar包,运行无法识别main函数,怎么办?
    Linux:krb5
    SqlServer数据库端口默认是1433吗?
    Linux下使用shell实现上传linux下某个目录下所有文件到ftp
    Spark+Hadoop+Hive集群上数据操作记录
    hadoop之 Hadoop2.2.0中HDFS的高可用性实现原理
    虚拟路由冗余协议VRRP
    hadoop 之Hadoop生态系统
    Oracle NoLogging Append 方式减少批量insert的redo_size
    Oracle常用的性能诊断语句
  • 原文地址:https://www.cnblogs.com/zjdxr-up/p/7375412.html
Copyright © 2020-2023  润新知