title: How to serialize a json containing LAZY associations
body: <p>I am having an <code>Person</code> entity which has <code>@ManyToOne</code> association with <code>Contact</code> entity with fetch type LAZY. I am using spring-boot to expose REST API. One of my POST call contains nested JSON to save the parent entity <code>Person</code> along with association <code>Contact</code> </p>
  
  <p>Since <code>Contact</code> fetch type is LAZY, I am encountering into following exception</p>
  
  <pre><code>    ERROR 17415 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 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) (through reference chain: com.example.rest.RestResultObject["results"]-&gt;java.util.ArrayList[0]-&gt;com.example.model.Person["contact"]-&gt;com.example.model.Contact_$$_jvst8d1_4["handler"])] with root cause
  
  com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 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) (through reference chain: com.example.rest.RestResultObject["results"]-&gt;java.util.ArrayList[0]-&gt;com.example.model.Person["contact"]-&gt;com.example.model.Contact_$$_jvst8d1_4["handler"])
  at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.9.3.jar:2.9.3]
  </code></pre>
  
  <p>Without changing Contact to EAGER. Is there any best way to solve this problem?</p>
  
  <p><strong>Updated:</strong></p>
  
  <p><strong>Person.java</strong></p>
  
  <pre><code>public class Person {
      private long id;
      private String name;
      private String rno;
      @ManyToOne(fetch = FetchType.LAZY)
      private Contact contact;
  
      // Getters and setters
  }
  </code></pre>
  
  <p><strong>Contact.java</strong></p>
  
  <pre><code>public class Contact {
      private long id;
      private String info;
      @OneToMany
      private List&lt;Person&gt; persons;
  }
  </code></pre>