org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.Mismat

专栏收录该内容

问题描述

SpringBoot接口报错

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT) at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 281] (through reference chain: xxxx["param"])


起初我以为是Mybatis查询出数据,转换的问题,后来发现压根没有执行到接口



问题发现

因为没有到接口,我的代码是这样的

public AjaxResult edit(@RequestBody Store Store)
{
    return toAjax(StoreService.updateStore(Store));
}

根据错误信息来查看,大意是,参数类型为String,但是获取的类型为Object,所以导致转换失败,我的param参数是String,查看了请求参数,其中的param是JSON字符串,所以导致了这个问题



问题解决

要么不使用 @RequestBody,自行处理接收参数

要么将Store的param改为Object类型

要么前端传递的param为字符串类型,我推荐这种,在前端 JSON.stringify(param) 就可以了




END

本文链接:https://sdpro.top/blog/html/article/1105.html

♥ 赞助 ♥

尽管去做,或许最终的结果不尽人意,但你不付出,他不付出,那怎会进步呢?