解决:com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_42969074/article/details/85268702

今天在使用Spring Data JPA的时候,碰到了这样一个问题:

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.thr.entity.User$HibernateProxy$xopzX9ty["hibernateLazyInitializer"])

这是因为在使用Json时,

fasterxml.jackson将对象转换为json报错

解决办法:

在实体类上面加上注解 @JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })

/**
 * @author Tang Haorong
 * @name
 */

@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
@Entity
@Table(name = "t_user")
public class User implements Serializable {

    @Id
    @Column(name = "id",nullable = false)
    @GeneratedValue
    private Integer id;

    @Column(name = "name",length = 64)
    private String name;

    @Column(name = "password",length = 64)
    private String password;

猜你喜欢

转载自blog.csdn.net/qq_42969074/article/details/85268702