Create CLOB property from JSON

我的梦境 提交于 2019-12-12 04:18:19

问题


I have Entity imported like a Maven dependency, looks like this(simplified)

@Entity
public class Person extends Base {

    private String name;

    private Clob biography;
//Getters and setters

And I receive this JSON with method POST

{"name":"John Doe",
"biography":"dragonborn"}

And I got this error

"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"

If "biography" was String, Person is created. How can i convert JSON property to java.sql.Clob property? The best solution will tuning ObjectMapper, but i would be glad to hear any advices. Thanks!


回答1:


Just use

@Lob
String biography

And in DDL for database initiate column as CLOB



来源:https://stackoverflow.com/questions/34906458/create-clob-property-from-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!