Avoid Jackson serialization on non fetched lazy objects

前端 未结 14 2009
终归单人心
终归单人心 2020-11-22 13:02

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

14条回答
  •  耶瑟儿~
    2020-11-22 13:30

    For those who came here looking to find the solution for Apache CXF-based RESTful service, the configuration that fixes it is below:

    
        
            
        
    
    
    
    

    Where HibernateAwareObjectMapper is defined as:

    public class HibernateAwareObjectMapper extends ObjectMapper {
        public HibernateAwareObjectMapper() {
            registerModule(new Hibernate5Module());
        }
    }
    

    The following dependency is required as of June 2016 (provided you're using Hibernate5):

    
        com.fasterxml.jackson.datatype
        jackson-datatype-hibernate5
        2.7.4
      
    

提交回复
热议问题