Strange Jackson exception being thrown when serializing Hibernate object

前端 未结 15 2784
离开以前
离开以前 2020-11-29 18:12

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

15条回答
  •  伪装坚强ぢ
    2020-11-29 18:57

    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{ }
    

提交回复
热议问题