我有实体像 Maven 依赖项一样导入,看起来像这样(简化的)
@Entity
public class Person extends Base {
private String name;
private Clob biography;
//Getters and setters
我通过 POST 方法收到这个 JSON
{"name":"John Doe",
"biography":"dragonborn"}
我收到了这个错误
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "Could not read document: Can not construct instance of java.sql.Clob,
problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information\n at
[Source: java.io.PushbackInputStream@39e31d6a; line: 2, column: 13] (through reference chain: com.example.Person[\"biography\"]);
nested exception is com.fasterxml.jackson.databind.JsonMappingException:
Can not construct instance of java.sql.Clob,
problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information\n
at [Source: java.io.PushbackInputStream@39e31d6a; line: 2, column: 13] (through reference chain: com.example.Person[\"biography\"])",
"path": "/persons"
如果“biography”是字符串,则创建 Person。 如何将 JSON 属性转换为 java.sql.Clob 属性? 最好的解决方案是调整 ObjectMapper,但我很高兴听到任何建议。谢谢!
最佳答案
只需使用
@Lob
String biography
在数据库的 DDL 中将列初始化为 CLOB
关于java - 从 JSON 创建 CLOB 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34906458/