Jackson is throwing a weird exception that I don\'t know how to fix. I\'m using Spring, Hibernate and Jackson.
I have already considered that lazy-loading is causing
You can add a Jackson mixin on Object.class to always ignore hibernate-related properties. If you are using Spring Boot put this in your Application class:
@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder() {
Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder();
b.mixIn(Object.class, IgnoreHibernatePropertiesInJackson.class);
return b;
}
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
private abstract class IgnoreHibernatePropertiesInJackson{ }
I got the same issue, salutations are here
Avoid Jackson serialization on non fetched lazy objects
http://blog.pastelstudios.com/2012/03/12/spring-3-1-hibernate-4-jackson-module-hibernate/
https://github.com/nessonqk/jackson-datatype-hibernate
You could use @JsonIgnoreProperties(value = { "handler", "hibernateLazyInitializer" })
annotation on your class "Director"
I faced the same issue and It is really strange that the same code works in few case whereas it failed in some random cases.
I got it fixed by just making sure the proper setter/getter (Making sure the case sensitivity)
I had the same problem. See if you are using hibernatesession.load()
. If so, try converting to hibernatesession.get()
. This solved my problem.
Similar to other answers, the problem for me was declaring a many-to-one column to do lazy fetching. Switching to eager fetching fixed the problem. Before:
@ManyToOne(targetEntity = StatusCode.class, fetch = FetchType.LAZY)
After:
@ManyToOne(targetEntity = StatusCode.class, fetch = FetchType.EAGER)