1

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?

asked Jun 12, 2021 at 8:08
3
  • Could you please show RequestEventDto as well. Commented Jun 12, 2021 at 15:10
  • Hi, @SternK I updated it in the question. Thanks Commented Jun 12, 2021 at 16:38
  • There must be another exception cause that tells you more about the actual issue. Attach the full stack trace. Commented Jun 14, 2021 at 13:30

1 Answer 1

2

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.

answered Jun 15, 2021 at 7:13
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.