Не найден сериализатор для класса org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor и не найдены свойства для создания BeanSerializer - PullRequest
0 голосов
/ 03 октября 2019

Я использую Spring Boot с Spring Data JPA. Однако, когда я пытаюсь получить данные из моего репозитория, выдается следующая ошибка:

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 - нет. Я что-то упускаю?

Мой класс покемонов - это простой класс POJO:

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
}

Ответы [ 2 ]

0 голосов
/ 08 октября 2019

Мне удалось решить проблему с помощью аннотации @JsonIgnoreProperties.

// package and imports

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties({"hibernateLazyInitializer"})
@Entity
public class Pokemon implements Serializable {

// rest of code

}
0 голосов
/ 03 октября 2019

Возможно, попробуйте добавить аннотацию к вашим полям, чтобы сопоставить имена столбцов с полями @Column (name = "name") private String name;

или вы добавили аннотацию к получателям и установщикам

...