我已经创建了一个宁静的Web服务,并且尝试发送上述课程的发帖请求
public class A {
Duration availTime;
}
public class MyRest {
@RequestMapping(value = "/test", method = RequestMethod.POST)
public Response<?> test(@RequestBody A ta) {
return new ResponseEntity<>(HttpStatus.OK);`
}
}
Run Code Online (Sandbox Code Playgroud)
原始请求主体
{
"availTime": {
"seconds": 5400,
"nano": 0,
"units": [
"SECONDS",
"NANOS"
]
}
}
Run Code Online (Sandbox Code Playgroud)
预期的json结果
{"availTime": "PT1H30M"}
Run Code Online (Sandbox Code Playgroud)
我收到了以上错误:无法读取HTTP消息:
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected token (START_OBJECT),
expected one of [VALUE_STRING, VALUE_NUMBER_INT, VALUE_NUMBER_FLOAT] for java.time.Duration value; nested exception is
com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected one of [VALUE_STRING, VALUE_NUMBER_INT, VALUE_NUMBER_FLOAT] for java.time.Duration value
Run Code Online (Sandbox Code Playgroud)