开发过程中碰到一个异常:
java.io.EOFException: No content to map to Object due to end of input

完整java异常:

java.io.EOFException: No content to map to Object due to end of input

org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2433) [jackson-mapper-asl-1.8.1.jar:1.8.1]

at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2366) [jackson-mapper-asl-1.8.1.jar:1.8.1]

at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1162) [jackson-mapper-asl-1.8.1.jar:1.8.1]

at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410) [jackson-jaxrs-1.8.1.jar:1.8.1]

这个问题困扰了我很久,最后发现原因是:

Content-Type我设置为 application/json charset=utf-8,但是实际传递参数至服务端时并没有传递json参数,导致at org.codehaus.jackson.map.ObjectMapper._readValue读取不到json数据导致报错。

解决办法:当不传递json数据时,’Content-Type’设置为’application/x-www-form-urlencoded charset=utf-8’即可。