How can one map a Java Map to a PostgreSQL json data type ?
Note that I want to map PostgreSQL-JSON-Data to a Java Map, and not to a String. Therefore I do not agree that my question is a duplicate of Mapping postgreSQL JSON column to Hibernate value type.
Entity example:
@Entity
public class Test implements Serializable {
...
@Column(name = "DATA")
private Map<String, Object> data = new HashMap<>();
...
}
Usage:
Test t = new Test();
t.getData().put("name", "James");
t.getData().put("number", 1);
t.getData().put("now", new Date());
Expected json when persisted:
{
"name" : "James"
"number" : 1,
"now" : 1438933526108
}