以前、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