Search code examples
javasqljsonspringclob

Create CLOB property from JSON


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!


Solution

  • Just use

    @Lob
    String biography
    

    And in DDL for database initiate column as CLOB