'No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer
I am using Spring Boot with Spring Data JPA. However, when I try to retrieve data from my Repository, the following error is thrown:
Type definition error: [simple type, class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.example.model.Pokemon$HibernateProxy$DuUnG9om[\"hibernateLazyInitializer\"])
Most of the "duplicates" I see have relationships, but my Pokemon class does not. Is there something that I am missing?
My Pokemon class is a simple POJO class:
package com.example.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Pokemon implements Serializable {
/**
*
*/
private static final long serialVersionUID = -2228784815938588107L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
private Double attack, defense, speed;
public Pokemon() {
}
public Pokemon(int id, String name, double attack, double defense, double speed) {
super();
this.id = id;
this.name = name;
this.attack = attack;
this.defense = defense;
this.speed = speed;
}
// Getters and setters
}
Solution 1:[1]
I was able to solve the issue by using the @JsonIgnoreProperties annotation.
// package and imports
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties({"hibernateLazyInitializer"})
@Entity
public class Pokemon implements Serializable {
// rest of code
}
Solution 2:[2]
Maybe try to add annotation to your fields, to map the column names with the fields @Column(name="name") private String name;
or did you put the annotation to the getters and setters?
Solution 3:[3]
With your repository, when you retrieve one Pokemon use the method :
findById(id).get();
Solution 4:[4]
What solved this issue for me was using jackson-datatype-hibernate5 and registering this module in objectmapper
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Stefan Creanga |
| Solution 3 | Yu Hao |
| Solution 4 | kqr |
