I have an entity, which is mapped to PostgreSQL, I want to use JSONB to be able to insert columns through JSON.
@Entity
@Table(name="TB_ORDEM_MANUTENCAO")
@TypeDef(
name = "jsonb",
typeClass = JsonBinaryType.class
)
public class OrdemManutencao implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO) // Cria automaticamente os ids
private long id;
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd")
private Date dataManutencao;
@OneToOne
@JoinColumn(name = "equipamento_id", unique = true)
private Equipamento equipamento;
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
private String propriedades;
}
In Swagger, I try to add a Maintenance Order as follows:
{
"propriedades" : [{"uf": "MG", "teste": "teste"}],
"dataManutencao": "2020-04-04",
"equipamento": {
"id": 13,
"nome": "Lavadoura",
"quantidade": 1
}
}
This does not insert the columns in my order_maintenance table, just insert like that:
Response body
{
"id": 27,
"dataManutencao": "2020-04-04",
"equipamento": {
"id": 13,
"nome": "Lavadoura",
"quantidade": 1
}
}
how can I do this?