I have a mapping problem between Java field and Jsonb column in postgres.
here is how my POJO looks like:
@TypeDefs({
@TypeDef(name = "CoreRuleConditionJsonb", typeClass = JsonbUserType.class, parameters = {
@org.hibernate.annotations.Parameter(name = JsonbUserType.CLASS, value = "com.ea.drsa.core.bre.database.CoreRuleConditionJsonb")
}),
@TypeDef(name = "CoreRuleActionJsonb", typeClass = JsonbUserType.class, parameters = {
@org.hibernate.annotations.Parameter(name = JsonbUserType.CLASS, value = "com.ea.drsa.core.bre.database.CoreRuleActionJsonb")
})
})
@Data
@Entity
@Builder
@Table(schema = "business_rules", name = "rules")
public class CoreRule {
@NotNull
@Type(type = "CoreRuleConditionJsonb")
private List<List<CoreRuleConditionJsonb>> conditions;
@NotNull
@Type(type = "CoreRuleActionJsonb")
private List<List<CoreRuleActionJsonb>> actions;
}
and data in postgres, for example actions:
[
[
{
"name": "Default rule for ACCEPTED and Appointment missions TOW",
"type": "SMS",
"media": {
"sendToDriver": true
},
"order": 1,
"resend": false,
"templateId": "285eS0KtNEBOMykhqJWIoo"
}
]
]
basically, I need to deserialize array of arrays from jsonb type. The error I am getting:
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
deserialize value of type `com.ea.drsa.core.bre.database.CoreRuleActionJsonb` from
Array value (token `JsonToken.START_ARRAY`)
at [Source: (String)"[[{"name": "SMS for ROS and HIGHWAY_ROS", "type": "SMS",
"media": {"sendToDriver": true}, "order": 1, "resend": false, "templateId":
"2nwKg5jBA27g15aJLmX4Av"}], [{"name": "SMS for ROS and HIGHWAY_ROS", "type": "SMS",
"media": {"sendToDriver": true}, "order": 2, "resend": false, "templateId":
"2nwKg5jBA27g15aJLmX4Av"}]]"; line: 1, column: 2] (through reference chain:
java.util.ArrayList[0])
can anyone please help to correctly configure the mapping?