Could not read document: Can not deserialize instance of java.lang.xxx out of START_OBJECT token
2017-12-16 14:21
761 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Tony_zt/article/details/78819720
Java 项目中遇到的问题:Could not read document: Can not deserialize instance of java.lang.String out of START_OBJECT token
前些日子在项目中遇到这样一个问题,调用一个方法时报错,特意记录下。
下面是控制台输出信息:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: java.io.PushbackInputStream@33b082c5; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: java.io.PushbackInputStream@33b082c5; line: 1, column: 1] at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:240) at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:225) at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:95) at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:917) at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:901) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:655) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531) at com.einwin.jd.utils.JDRequestUtil.postForEntityWithOutToken(JDRequestUtil.java:91) at com.einwin.jd.utils.JDRequestUtil.postForEntity(JDRequestUtil.java:61) at com.einwin.jd.utils.JDRequestUtil.postForEntity(JDRequestUtil.java:36) at com.einwin.jd.client.OrderClient.comfirmReceipt(OrderClient.java:253) at com.einwin.test.OrderTest.comfirmReceipt(OrderTest.java:223) 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token ...
由消息日志可以看出,它报了HttpMessageNotReadableException消息不可读异常和JsonMappingException JSON映射异常,由此知是由于JSON映射不一致而导致HttpMessageNotReadableException
一般情况下是由于你请求回来的数据是json类型,而你用来接收的参数类型不是json类型造成的。或者是其他返回参数和接收参数不一致造成的,仔细检查代码,改为一致即可。
相关文章推荐
- Could not read document: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token
- Could not read JSON: Can not deserialize instance of java.lang.Integer out of START_OBJECT token
- Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token
- Jackson错误:Can not deserialize instance of java.lang.String out of START_OBJECT token
- Can not deserialize instance of java.lang.String out of START_OBJECT token
- Could not read JSON: Can not deserialize instance of java.lang.String[] out of VALUE_STRING token
- Can not deserialize instance of java.lang.String out of START_OBJECT token
- Could not read JSON: Can not deserialize instance of out of START_ARRAY token
- 解决用户自生成meta导入kylin后报错问题Can not deserialize instance of java.lang.String[] out of VALUE_STRING token
- Can not deserialize instance of java.util.ArrayList out of VALUE_FALSE token
- Jackson反序列化提示:Can not deserialize instance of Task out of START_ARRAY token
- Cannot deserialize instance of java.lang.String out of START_ARRAY/START_OBJECT token,RestTemplate小坑
- JNI DETECTED ERROR IN APPLICATION: can't call void XXX on instance of java.lang.Class <XXX>解决方案
- HIbernate 3.2 java.lang.IllegalArgumentException: object is not an instance of declaring class
- nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
- selenium cant start a new browser(ie7):java.lang.StringIndexOutOfBoundsException: String index out of range: -1
- java.lang.IllegalArgumentException: object is not an instance of declaring class
- Tomcat的异常 之 java.lang.IllegalArgumentException: Document base xxx does not exist or is not a readab
- 异常笔记(2)--object is not an instance of declaring class while invoking public abstract java.lang.Long
- Tomcat异常:Illegal access: this web application instance has been stopped already. Could not load java.lang.Object.