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

  • 相关阅读:
    (转)上海驾照到期换证流程及注意事项
    sql 获取批处理信息的脚本(优化器在处理批处理时所发生的优化器事件)
    C# xml通过xslt转换为html输出
    C#基础 继承和实例化
    sqlserver 获取数据库、表和字段相关信息
    Json反序列化为动态类型(dynamic)
    Aspose.cells常用用法1
    C# 生成缩略图 去除图片旋转角度
    C# 压缩图片到指定宽度,假如图片小于指定宽度 判断图片大小是否大于指定大小(KB) 如果大于则压缩图片质量 宽高不变
    C# 2个List<T>比较内部项是否相等
  • 原文地址:https://www.cnblogs.com/zjdxr-up/p/7375412.html
Copyright © 2020-2023  润新知