博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
阅读量:5951 次
发布时间:2019-06-19

本文共 5862 字,大约阅读时间需要 19 分钟。

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

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

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

 

你可能感兴趣的文章
2011工作总结
查看>>
Java学习笔记二:Java开发工具Eclipse的安装与使用
查看>>
3.4-ansible远程执行脚本
查看>>
常见邮件服务器(接收服务器和发送邮件服务器)地址
查看>>
系统监控Zabbix部署文档
查看>>
我的友情链接
查看>>
计算机网络练习题(一)
查看>>
Web服务器技术的优缺点
查看>>
gpg命令
查看>>
AndroidMainfest.xml文件解释
查看>>
格式化的盘要怎样寻回资料
查看>>
硬盘格式化了的资料恢复方案
查看>>
centOS6.5 源码编译安装zabbix-server
查看>>
站在0基础的角度--看网络
查看>>
PHP检测终端设备是平板、手机还是电脑
查看>>
win10安装oracle12c遇到[FATAL] [DBT-10304]
查看>>
python数据结构与算法(14)
查看>>
python之Linux基础(十)
查看>>
muma很可能在陪你玩游戏
查看>>
配置IP地址
查看>>