Reputation: 21
I have a Postgres table that has nullable columns of type JSONB.
On my Hibernate Entity (extends PanacheBaseEntity), I have a field as follows
@Column(name = "my_column")
@JdbcTypeCode(SqlTypes.JSON_ARRAY)
private JsonArray myColumn;
The setup works fine if my column actually contains a JSON array, but if the column itself is NULL, then the code throws an error saying (paraphrasing)
Cannot set Tuple$1 to: [my.package.Class.myColumn] (setter) of type JsonArray
I'd expect that my field would just be null
, as the default for nullable
is true
in the @Column
annotation.
Upvotes: 0
Views: 17
Reputation: 21
Okay, I figured out the cause.
The value in the database wasn't null
, but we had accidentally inserted the literal string "null"
, which of course isn't a well formed JSON object, but is also not null
from a Java or SQL perspective.
Hence, it wasn't able to be de-serialized correctly, leading to the error.
Upvotes: 0