Put请求数据格式异常
来源:9-9 Spring消息编程模型01-编写生产者

_季步
2020-09-10
Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "{id}"]
json:
{ "id": 1, "auditStatusEnum": "PASS", "reason": "这是一个优秀的赚钱工具" }
@RestController @RequestMapping("/admin/shares") @RequiredArgsConstructor(onConstructor = @_(@Autowired)) public class ShareAminController { private final ShareService shareService; @PutMapping("/audit/{id}") public Share auditById(@PathVariable Integer id,@RequestBody ShareAuditDTO auditDTO){ // TODO 认证、授权 return this.shareService.auditById(id,auditDTO); } }
Json传到后端的数据是String,但是id是Integer,这是json格式的问题吗
为什么视频里直接都不需要id了
我吧json去掉id,只传递auditStatusEnum和reason也还是报错
如果id改成String类型,调用auditById的时候进行转换是能用的,但是为啥Integer就用不了呢
@PathVariable如果替换成@RequestBody则是另一个错误
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.Integer` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.Integer` out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1]]
id改成String类型又有其它的错误,这个错误应该是RocketMQ引起的,但是RocketMQ是正常启动的呀...
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.itmuch.contentcenter.dto.messaging.UserAddBounsMsgDTO$UserAddBounsMsgDTOBuilder and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
写回答
2回答
-
大目
2020-09-11
{ "id": 1, "auditStatusEnum": "PASS", "reason": "这是一个优秀的赚钱工具" }
为啥RequestBody里面有id这个field吗?
这是第一,从您截图的代码来看,你请求的url应该是/admin/shares/id
消息体是
{ "auditStatusEnum": "PASS", "reason": "这是一个优秀的赚钱工具" }
022020-09-12 -
_季步
提问者
2020-09-10
return this.shareService.auditById(Integer.valueOf(id),auditDTO);
虽然valueOf()可以解决,方式有更好解决方式吗?造成这样的原因是什么
00
相似问题