I am searching on this problem for two days now, without a proper solution.
I have a PostgreSQL-Database with a table:
CREATE TABLE mytable (key text PRIMARY KEY, content text)
Further, I have a Java SpringBoot-Application with a JPA entity class:
@Entity
@Table(name = "mytable")
public class MyEntity {
@Id
private String key;
// tell JPA to convert MyPojo to JSON using the default Jackson ObjectMapper
private MyPojo content;
// constructors, getters, setters
}
The MyPojo class contains sub-structure involving basic types, Maps, Lists, and other nested POJO classes. It does not seem convenient to write a Converter for the MyPojo class and all the other nested POJO classes. Instead, I want to use Jackson to serialize/deserialize it.
How do I configure Jackson/JPA to store a MyPojo object as a JSON string in the text field of the database table? I was hoping for a suitable Annotation like @Convert(converter=Jackson.ObjectMapper). Introducing an additional String field to the MyEntity class was another approach that would not work.
I sucessfully used Jackson to send/parse MyPojo objects as JSON strings to a REST interface, but I'm struggling to put the same string into the text field of a database.