反序列化时,字段接受非数组,但是传入的是数组
@PostMapping(path = "/aa", produces = { "application/json;charset=UTF-8" }, consumes= {"application/json;charset=UTF-8"}) @ResponseBody public Object post(@RequestBody Foo foo) { return "{}"; } public class Foo { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
序列使用的是 com.fasterxml.jackson.databind.ObjectMapper
测试:
curl -H "Content-Type:application/json;utf-8" -X POST -d "{\"name\":[\"1\",\"2\"]}" http://localhost:8888/aa
结果复现:
JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token;
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token
at [Source: (PushbackInputStream); line: 1, column: 9] (through reference chain: cn.zno.Foo[\"name\"])
- deserialize START_ARRAY instance Cannot Stringdeserialize start_array instance cannot representation deserialize cannot string deserialize方法cannot string value pushbackinputstream deserialize start_array components function cannot string numberformatexception cannot string问题 start_array deserialize deserialization deserializing