I have a simple controller that return a User object, this user have a attribute coordinates that have the hibernate property FetchType.LAZY.
When I try to get this
I've spent whole day trying to solve the same problem. You can do it without changing existing message converters configuration.
In my opinion the easiest way to solve this problem only with 2 steps with help of jackson-datatype-hibernate:
kotlin example (same as java):
build.gradle.kts
:implementation("com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:$jacksonHibernate")
@Bean
@Bean
fun hibernate5Module(): Module = Hibernate5Module()
Notice that Module
is com.fasterxml.jackson.databind.Module
, not java.util.Module
Also good practice is to add @JsonBackReference & @JsonManagedReference
to @OneToMany
& @ManyToOne
relationships. @JsonBackReference
could be only 1 in class.