在用HuTool的HttpRequest发送实体类的json字符串时报错:
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `com.lulu.sdk.model.User` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.lulu.sdk.model.User` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 2]]
这个异常是springmvc的处理器无法将json串转成@RequestBody标注的实体类,
原因是我定义的这个实体类没有无参构造,Jackson(一个流行的Java JSON库)无法从提供的JSON数据中创建实体类的实例
同时实体类属性要保证有set方法