java - 从 JSON 创建 CLOB 属性

标签 java sql json spring clob

我有实体像 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/

相关文章:

java - 碰撞检测机器人(与小行星!!)

php - 准备好的语句不返回结果

c# - 从无线连接的 Arduino 异步绘制数据的最佳库或方法

java - 如何在运行时从类路径中删除 jar 文件?

java - 我们如何在 Maven 应用程序的构建过程中从 JSP 生成静态 HTML 文件

sql - 您可以使用 .bat 文件编写 sql 命令吗?

MySQL 更新性能非常糟糕

php - 来自 MySQL 查询的 Jquery 多维 JSON

php - 从 php 到 iOS 应用程序的 json 响应不完整

android - 在 Android 中以 Json 对象的形式获取 Retrofit 结果