找不到针对类org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor的序列化器 [英] No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor
问题描述
当我尝试导航至端点时,出现以下错误
When i try to navigat to an endpoint i get tho following error
类型定义错误:[简单类型,类org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor];嵌套的异常是com.fasterxml.jackson.databind.exc.InvalidDefinitionException:未为类org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor找到序列化器,也未找到创建BeanSerializer的属性(为避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)>
我检查了所有模型,所有属性都有getter和setter.那是什么问题呢?
I checked all my models and all the attributes have getters and setters. So what's the problem ?
我可以通过添加spring.jackson.serialization.fail-on-empty-beans=false
来解决此问题,但是我认为这只是隐藏异常的一种解决方法.
I can fix that by adding spring.jackson.serialization.fail-on-empty-beans=false
but i think this is just a work around to hide the exception.
修改
Product
型号:
@Entity
public class Product {
private int id;
private String name;
private String photo;
private double price;
private int quantity;
private Double rating;
private Provider provider;
private String description;
private List<Category> categories = new ArrayList<>();
private List<Photo> photos = new ArrayList<>();
// Getters & Setters
}
PagedResponse
类别:
public class PagedResponse<T> {
private List<T> content;
private int page;
private int size;
private long totalElements;
private int totalPages;
private boolean last;
// Getters & Setters
}
RestResponse
类别:
public class RestResponse<T> {
private String status;
private int code;
private String message;
private T result;
// Getters & Setters
}
在我的控制器中,我返回 ResponseEntity<RestResponse<PagedResponse<Product>>>
In my controller i'm returning ResponseEntity<RestResponse<PagedResponse<Product>>>
推荐答案
您可以通过
@JsonIgnore
或者如果您有任何具有关系的延迟加载属性.您可以在属性顶部使用此注释.
Or If you have any lazy loaded properties having a relationship. You can use this annotation at top of the property.
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
示例:
@Entity
public class Product implements Serializable{
private int id;
private String name;
private String photo;
private double price;
private int quantity;
private Double rating;
private Provider provider;
private String description;
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
private List<Category> categories = new ArrayList<>();
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
private List<Photo> photos = new ArrayList<>();
// Getters & Setters
}
如果仍然存在此错误,请在您的application.properties文件中添加此行代码
If you still have this error, please add this line of code in your application.properties file
spring.jackson.serialization.fail-on-empty-beans=false
希望您的问题能得到解决.谢谢.
I hope your problem will be solved. Thanks.
这篇关于找不到针对类org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor的序列化器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!