简体   繁体   English

这个错误是什么'org.springframework.http.converter.HttpMessageNotReadableException:无法读取JSON:无法反序列化实例'是什么意思?

[英]What does this error 'org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance' mean?

I am trying to send a JSON array to my server. 我正在尝试将JSON数组发送到我的服务器。 My JSON array looks like this 我的JSON数组看起来像这样

["{"sourceAccountNo":"555555555555555","sourceBankCode":"GLBBNPKA","destinationBankCode":"GLBBNPKA","destinationBankAccountNo":"123456789111111","amount":5000,"narrationOne":"txn4 by maker 1","uniqueId":"ESW-COR:1405507591784"}"]

And the corresponding server side method is : 相应的服务器端方法是:

   @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    @RequestMapping(value = "/xxx", method = RequestMethod.POST)
    public ResponseEntity<BulkCorporatePaymentResponse> xxx(@RequestBody BulkCorporatePaymentRequest corporatePaymentRequestList) {
            BulkCorporatePaymentResponse response = null;
            try {
                response = corporateApi.processBulkFundTransfer(corporatePaymentRequestList);
            } catch (Exception e) {

            }
            return new ResponseEntity<BulkCorporatePaymentResponse>(response, HttpStatus.OK);
        }

Now my BulkCorporatePaymentResponse and BulkCorporatePaymentRequest look like this 现在我的BulkCorporatePaymentResponse和BulkCorporatePaymentRequest看起来像这样

public class BulkCorporatePaymentResponse implements Serializable {

    private static final long serialVersionUID = -2026566288888889L;
    List<CorporatePaymentResponse> paymentResponseList;

    public List<CorporatePaymentResponse> getPaymentResponseList() {
        return paymentResponseList;
    }

    public void setPaymentResponseList(List<CorporatePaymentResponse> paymentResponseList) {
        this.paymentResponseList = paymentResponseList;
    }
}


public class BulkCorporatePaymentRequest implements Serializable {

    private static final long serialVersionUID = -202656628880099889L;
    private List<CorporatePaymentRequest> paymentRequestlist;

    public List<CorporatePaymentRequest> getPaymentRequestlist() {
        return paymentRequestlist;
    }

    public void setPaymentRequestlist(List<CorporatePaymentRequest> paymentRequestlist) {
        this.paymentRequestlist = paymentRequestlist;
    }

}

And my CorporatePaymentRequest looks liks this 我的CorporatePaymentRequest看起来很喜欢这个

public class CorporatePaymentRequest implements Serializable {




    private static final long serialVersionUID = 1346864799470440670L;

    private String sourceAccountNo;
    private String sourceBankCode;

    private String destinationBankCode;
    private String destinationBankAccountNo;

    private String corporateName;
    private double amount;
    private String remarks;

    private String narrationOne;
    private String narrationTwo;

    private String uniqueId;

    public String getSourceAccountNo() {
        return sourceAccountNo;
    }

    public void setSourceAccountNo(String sourceAccountNo) {
        this.sourceAccountNo = sourceAccountNo;
    }

    public String getSourceBankCode() {
        return sourceBankCode;
    }

    public void setSourceBankCode(String sourceBankCode) {
        this.sourceBankCode = sourceBankCode;
    }

    public String getDestinationBankCode() {
        return destinationBankCode;
    }

    public void setDestinationBankCode(String destinationBankCode) {
        this.destinationBankCode = destinationBankCode;
    }

    public String getDestinationBankAccountNo() {
        return destinationBankAccountNo;
    }

    public void setDestinationBankAccountNo(String destinationBankAccountNo) {
        this.destinationBankAccountNo = destinationBankAccountNo;
    }

    public String getCorporateName() {
        return corporateName;
    }

    public void setCorporateName(String corporateName) {
        this.corporateName = corporateName;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getNarrationOne() {
        return narrationOne;
    }

    public void setNarrationOne(String narrationOne) {
        this.narrationOne = narrationOne;
    }

    public String getNarrationTwo() {
        return narrationTwo;
    }

    public void setNarrationTwo(String narrationTwo) {
        this.narrationTwo = narrationTwo;
    }

    public String getUniqueId() {
        return uniqueId;
    }

    public void setUniqueId(String uniqueId) {
        this.uniqueId = uniqueId;
    }

}

And whenever i try to pass the above mentioned json array to my server I get the following exception 每当我尝试将上面提到的json数组传递给我的服务器时,我得到以下异常

Jul 22, 2014 4:53:38 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [esewarest] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of com.esewa.server.corporate.schema.BulkCorporatePaymentRequest out of START_ARRAY token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@72ced13f; line: 1, column: 1]; nested exception is org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.esewa.server.corporate.schema.BulkCorporatePaymentRequest out of START_ARRAY token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@72ced13f; line: 1, column: 1]] with root cause
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.esewa.server.corporate.schema.BulkCorporatePaymentRequest out of START_ARRAY token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@72ced13f; line: 1, column: 1]
    at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:212)
    at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromArray(BeanDeserializer.java:869)
    at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:597)
    at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2725)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1916)
    at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal(MappingJacksonHttpMessageConverter.java:122)
    at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:153)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.readWithMessageConverters(HandlerMethodInvoker.java:641)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestBody(HandlerMethodInvoker.java:605)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:354)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:206)
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:179)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.esewa.server.web.filter.GWTCacheControlFilter.doFilter(GWTCacheControlFilter.java:36)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

Any suggestion would be of great help. 任何建议都会有很大帮助。

UPDATE by editor (Mona Jalal): On a side note I get this error when posting raspi IP to Postman and click on the send button: 编辑器更新(Mona Jalal):在旁注中,我将raspi IP发布到Postman并点击发送按钮时出现此错误:

144.92.129.230:8080/api/devices

{
  "timestamp": 1457494478717,
  "status": 400,
  "error": "Bad Request",
  "exception": "org.springframework.http.converter.HttpMessageNotReadableException",
  "message": "Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter@53cb13b3",
  "path": "/api/devices"
}

Clearly, the JSON parser is unable to parse your JSON. 显然,JSON解析器无法解析您的JSON。 Try validating the JSON at http://jsonlint.com/ to see what the problem is. 尝试在http://jsonlint.com/验证JSON以查看问题所在。

As others have mentioned, you have an extraneous set of quotes just inside your initial square brackets. 正如其他人所提到的,你在初始方括号内有一组多余的引号。

You must remove these. 你必须删除这些。 If the conversion still doesn't work, you may have additional problems with the mapping of your JSON to your object, but don't confuse the two issues and put the quotes back - you will get nowhere with that approach - you need valid JSON first, then you can work on making sure that the valid JSON can be deserialized into the expected object. 如果转换仍然不起作用,您可能在将JSON映射到对象时遇到其他问题,但不要混淆这两个问题并将引号放回去 - 您将无法使用该方法 - 您需要有效的JSON首先,您可以确保可以将有效的JSON反序列化为预期的对象。

Perhaps a unit test for the JSON deserialization is in order? 也许JSON反序列化的单元测试是有序的?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException - Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException 无法实例化Json对象org.springframework.http.converter.HttpMessageNotReadableException - Cannot Instantiate Json Object org.springframework.http.converter.HttpMessageNotReadableException org.springframework.http.converter.HttpMessageNotReadableException - org.springframework.http.converter.HttpMessageNotReadableException 处理 DefaultHandlerExceptionResolver :org.springframework.http.converter.HttpMessageNotReadableException:JSON 解析错误:意外字符 - Handle DefaultHandlerExceptionResolver : org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character 如何处理 Spring 中的“org.springframework.http.converter.HttpMessageNotReadableException: JSON 解析错误”? - How to handle "org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error" in Spring? Rest API测试org.springframework.http.converter.HttpMessageNotReadableException - Rest API Testing org.springframework.http.converter.HttpMessageNotReadableException org.springframework.http.converter.HttpMessageNotReadableException:缺少所需的请求正文 - org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing 发送POST请求时org.springframework.http.converter.HttpMessageNotReadableException - org.springframework.http.converter.HttpMessageNotReadableException when sending a POST request 已解决 [org.springframework.http.converter.HttpMessageNotReadableException: JSON 解析错误:非法字符((CTRL-CHAR,代码 31)) - Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Illegal character ((CTRL-CHAR, code 31)) 无法读取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException:提取调用中缺少必需的请求正文 - Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing From a Fetch Call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM