Создать свойство CLOB из JSON

У меня Entity импортирован как зависимость Maven, выглядит так (упрощенно)

@Entity
public class Person extends Base {

    private String name;

    private Clob biography;
//Getters and setters

И я получаю этот JSON методом POST

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

Если "биография" была строкой, создается Person. Как преобразовать свойство JSON в свойство java.sql.Clob? Лучшим решением будет настройка ObjectMapper, но буду рад услышать любые советы. Спасибо!


person Snowy    schedule 20.01.2016    source источник


Ответы (1)


Просто используйте

@Lob
String biography

И в DDL для базы данных инициировать столбец как CLOB

person Snowy    schedule 17.04.2016