Postgres JsonBinaryType is not working with Upgrade to SpringBoot Version 3.1.5

169 views Asked by At

I have a SpringBoot project which persists data to a Postgres JsonB Column. So I am using the @TypeDef annotation in entity class, but after upgrading to SpringBoot Version 3.1.5 this annotation is no longer available.

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.annotations.Type;
//import org.hibernate.type.SqlTypes;
import org.json.simple.JSONObject;

@Entity
@Table(name = "myTable")
@TypeDef(name = "jsonb", typeClass = JsonBinaryType::class) // Typedef is not available
data class MyEntity(
    @Id
    @Column(unique = true, nullable = false, updatable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)   
    private UUID id;

    @Type(type = "jsonb") 
    @Column(nullable = true) 
    private JSONObject objConfig;
)

I tried using @JdbcTypeCode(SqlTypes.JSON) instead of @Type but at runntime I am getting

Could not write JSON: Can't resolve required map value type for class org.json.simple.JSONObject

I tried hibernate-core 6.1.6.Final too

1

There are 1 answers

0
Vishal kumar On

I have solved it as: Using Map instead of JSON OBject

import com.fasterxml.jackson.annotation.JsonProperty;
import io.hypersistence.utils.hibernate.type.json.JsonType;

@JsonProperty
@Type(JsonType.class)
@Column(columnDefinition = "jsonb")
private Map<String, Object> config;