title: Configuring Jackson to enable self-referencing objects using jackson-datatype-hibernate
body: <p>How do I configure the Jackson ObjectMapper in Spring Data when using Spring Boot?</p>
  
  <p>When I try returning a self-referencing entity I keep getting a <code>"com.fasterxml.jackson.databind.JsonMappingException: 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"</code> error when I try to retrieve the children of an object in a self-referencing table.</p>
  
  <p>I thought the issue was a serialization issue that could be solved by using the jackson-datatype-hibernate package to help me serialize self-referencing objects.
  <a href="https://github.com/FasterXML/jackson-datatype-hibernate" rel="nofollow">https://github.com/FasterXML/jackson-datatype-hibernate</a></p>
  
  <p>I haven't been able to see any definitive guidance so far on how to configure the existing ObjectMapper instance that Spring Data Rest uses.</p>
  
  <p>According to the project's GitHub page all I need to do is subclass the ObjectMapper</p>
  
  <pre><code>public class HibernateAwareObjectMapper extends ObjectMapper {
  
      public HibernateAwareObjectMapper() {
          registerModule(new Hibernate4Module());
      }
  }
  </code></pre>
  
  <p>However, if I subclass the ObjectMapper won't I loose the default behavior of the Jackson ObjectMapper? I don't necessarily want to lose that behavior, just extend it. Also, wouldn't I need to put an <code>@Component</code> annotation on the class in order to have Spring pick it up?</p>