解决springMVC接收json数据报错:Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

springMVC中的controller方法:

@ResponseBody
@PostMapping("/proxyInterfaceInfo")
public RpcResponse<ProxyInterfaceInfoRpcResponse> proxyInterfaceInfo(@RequestBody ProxyInterfaceInfoRpcRequest gwRequest) {

return null;
}

controller参数类:

@Setter
@Getter
public class ProxyInterfaceInfoRpcRequest extends BaseRequest{
	private static final long serialVersionUID = -5187407229562570847L;
	private Long subsidyId;
	private String interfaceCode;
	private String jsonData;
}

客户端请求:
客户端请求
客户端发送请求后,controller报异常:

2019-12-29 17:42:20.110 [http-nio-9986-exec-2] WARN  o.s.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver 140 - Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
 at [Source: (PushbackInputStream); line: 1, column: 54] (through reference chain: com.poly.pc.gateway.v1_0.struct.subsidy.request.ProxyInterfaceInfoRpcRequest["jsonData"])]

解决办法:
controller参数类ProxyInterfaceInfoRpcRequest的属性jsonData的类型改为Object即可:

@Setter
@Getter
public class ProxyInterfaceInfoRpcRequest extends BaseRequest{
	private static final long serialVersionUID = -5187407229562570847L;
	private Long subsidyId;
	private String interfaceCode;
	private Object jsonData;
}

可以这么理解,客户端提交的参数:

{"subsidyId":14,"interfaceCode":"TDJK001","jsonData":{"code":"Test001","muser":"00000000001"}}

这里的jsonData也被认为是一个复杂对象,而不是简单的String字符串。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值