Akila Wickramarachchi
Akila Wickramarachchi

Reputation: 53

jsonb type data saving with postgres db and spring boot getting JpaSystemException after java 8 to java 11 migration

I'm trying to save jsonb type data to a Postgres db table using the following library

   <dependency>
            <groupId>com.vladmihalcea</groupId>
            <artifactId>hibernate-types-52</artifactId>
            <version>2.11.1</version>
   </dependency>
   <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.14</version>
   </dependency>

In java 8 it worked without any issue, But due to requirement I had to migrate the service to java 11 but after the migration when I tried to save jsonb to the table I got the following error.

org.springframework.orm.jpa.JpaSystemException: java.lang.IllegalArgumentException: The given byte array cannot be transformed to Json object; nested exception is org.hibernate.HibernateException: java.lang.IllegalArgumentException: The given byte array cannot be transformed to Json object.

NOTE - Hibernate versions are the same in both java 8 and java 11 version: 5.4.20.Final in both

Following is the entity which trying to save

@Builder(toBuilder = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "test")
@TypeDefs({
        @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class),
})
public class Test extends Auditable {

    @Id
    @Column(name = "id", updatable = false, nullable = false, unique = true)
    private UUID id;

    @Type(type = "jsonb")
    @Column(name = "data", columnDefinition = "jsonb")
    private RequestEventDto data;

}

following is the RequestEventDto

import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
@Builder
public class RequestEventDto {
    private String requestId;

    @Builder.Default
    private String applicationId = "program1";

    private String entityType;
    private List<Map<String, Object>> listEntities;
}

Can you help with this problem?

Upvotes: 1

Views: 5389

Answers (1)

Akila Wickramarachchi
Akila Wickramarachchi

Reputation: 53

Issue fixed with adding the following annotations to the RequestEventDto

@NoArgsConstructor
@AllArgsConstructor
public class RequestEventDto {

It seems it is due to the constructor not there when serialization happening.

Upvotes: 2

Related Questions