This is my entity class that is mapped to a table in postgres
(9.4)
I am trying to store metadata as jsonb
type in the database
@Entity
@Table(name = “room_categories”)
@TypeDef(name = “jsonb”, typeClass = JsonBinaryType.class)
public class RoomCategory extends AbstractEntity implements Serializable {
private String name;
private String code;
@Type(type = "jsonb")
@Column(columnDefinition = "json")
private Metadata metadata;
}
This is the metadata class:
public class Metadata implements Serializable {
private String field1;
private String field2;
}
I have used following migration file to add jsonb
column:
databaseChangeLog:
– changeSet:
id: addColumn_metadata-room_categories
author: arihant
changes:
– addColumn:
schemaName: public
tableName: room_categories
columns:
– column:
name: metadata
type: jsonb
I am getting this error while creating the record in postgres
:
ERROR: column “metadata” is of type jsonb
but expression is of type bytea
Hint: You will need to rewrite or cast the expression.
This is the request body i am trying to persist in db:
{
“name”: “Test102”,
“code”: “Code102”,
“metadata”: {
“field1”: “field11”,
“field2”: “field12”
}
}
Please help how to convert bytea
type to jsonb
in java spring boot app