0

This question seems to be the same as this No serializer found for class org.hibernate.proxy.pojo.javassist.Javassist?. But there are some differences. The author of that question has lazy relationships. Instead, my entity is so simple:

@Entity
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Length(min = 5, max = 50, message = "error.firstName.length")
    @Column(name = "first_name")
    private String firstName;

    @Length(min = 5, max = 50, message = "error.lastName.length")
    @Column(name = "last_name")
    private String lastName;

    public User(Long id, String firstName, String lastName) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public User(String firstName, String lastName) {
        this(null, firstName, lastName);
    }

    public User() {}

    // getters & setters

}

but I still get this error:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: ua.savenkodenys.user_management.persistence.entity.User_$$_jvst11c_0["handler"]) (in the error description)

I also want to know what is this - (through reference chain: ua.savenkodenys.user_management.persistence.entity.User_$$_jvst11c_0["handler"]) (in the error description).

ua.savenkodenys.user_management.persistence.entity - these are my packages
not a Programmer
  • 175
  • 1
  • 14

1 Answers1

1

jackson-datatype-hibernate accommodates JSON serialization/deserialization with lazy-loaded objects.

With lazy-loading, a proxy object stands in for your object until your object can be retrieved from the database, so that's what the reference chain is referring to.

This question may be a duplicate, so try implementing the configuration class mentioned there first.

Alternatively, you could try adding the following annotation to your User entity, though this merely masks the problem rather than solving it.

@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
Philip Wrage
  • 1,505
  • 1
  • 12
  • 23