从 JSON 创建 CLOB 属性

Create CLOB property from JSON

我有实体 像 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" 是 String,则创建 Person。 如何将 JSON 属性 转换为 java.sql.Clob 属性? 最好的解决方案是调整 ObjectMapper,但我很乐意听到任何建议。谢谢!

只需使用

@Lob
String biography

并且在数据库的 DDL 中将列初始化为 CLOB