找不到针对类org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor的序列化器,也未找到创建BeanSerializer的属性 [英] No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered to create BeanSerializer

查看:457
本文介绍了找不到针对类org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor的序列化器,也未找到创建BeanSerializer的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Spring Boot与Spring Data JPA一起使用.但是,当我尝试从存储库中检索数据时,会引发以下错误:

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\"])

我看到的大多数重复项"都有关系,但是我的Pokemon类却没有关系.有什么我想念的吗?

Most of the "duplicates" I see have relationships, but my Pokemon class does not. Is there something that I am missing?

我的Pokemon类是一个简单的POJO类:

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
}

推荐答案

我能够通过使用@JsonIgnoreProperties注释解决此问题.

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

}

这篇关于找不到针对类org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor的序列化器,也未找到创建BeanSerializer的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆