以前、Domaを使ってSpring Boot アプリケーションからPostgresに接続した
これに追加で、JSON型のカラムを用意したい
## Entity Entityにプロパティを追加する
方はStringで定義する
@Id @Column(name = "search_condition") String searchCondition;
アプリケーション
アプリケーション側では、Jacksonを使ってJSON文字列に変換したものをEntityにセットする
PropertyMapping propertyMapping = new PropertyMapping(); ObjectMapper mapper = new ObjectMapper(); String condition = mapper.writeValueAsString(searchCondition); propertyMapping.setSearchCondition(condition);
SQL
最後にINSERTするsqlファイルでは例えば次のように::jsonbをつけて定義する
/*update.searchCondition*/'search_condition'::jsonb