title: Two way relationship with JsonBackReference & JsonManagedReference
body: <p><strong>ANSWER</strong></p>
  
  <p>I'll solve my problem regarding to this blog <a href="http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion" rel="nofollow noreferrer">Jackson – Bidirectional Relationships</a></p>
  
  <p>Thanks you.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>The problem is about <strong>JsonBackReference</strong> and <strong>JsonManagedReference</strong> annotations.
  With my two way relationship, I have to explicitly select one way for serialization with JsonBackReference and JsonManagedReference.
  But here, I am in case to use the opposit way "<em>Parent->Child</em>" for a specific requierement (using the way "<em>Child->Parent</em>" by default)
  When I inversed those two annotations, my JSON is what I'm looking for, for the special requierment.
  Any idea on how to use JACKSON in a two way relationship ?</p>
  
  <p>Thank you.</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Here is a code simple using EntityGraph (thanks to @NeilStockton suggestion), but still don't serialize the lazy attribute in JSON :-(</p>
  
  <p>Parent</p>
  
  <pre><code>@Entity
  public class Parent {
      @Id
      @GeneratedValue
      private Long id;
  
      @column
      private String parentAttribute;
  
      @OneToOne(mappedBy = "parent", optional = false)
      @JsonBackReference
      private Child child;
  </code></pre>
  
  <p>Child</p>
  
  <pre><code>@Entity
  public class Child {
      @Id
      @GeneratedValue
      private Long id;
  
      @column
      private String childAttribute;
  
      @OneToOne(optional = false, cascade = CascadeType.ALL)
      @JsonManagedReference
      private Parent parent;
  </code></pre>
  
  <p>Parent Repository</p>
  
  <pre><code>public interface ParentRepository extends CrudRepository&lt;Parent&gt; {
  
      @EntityGraph(attributePaths = { "child" })
      //a hack to use findAll with default lazy/eager mapping
      Collection&lt;Parent&gt; findByIdNotNull(); 
  }
  </code></pre>
  
  <p>Generated query :</p>
  
  <pre><code>Hibernate: 
      select
          parent0_.id as id1_33_0_,
          child1_.id as id1_32_1_,
          parent0_.parent_attribute as parent_attribute2_33_0_,
          child1_.child_attribute as child_attribute2_32_1_,
      from
          test.parent parent0_ 
      left outer join
          test.child child1_ 
              on parent0_.id=child1_.parent_id 
      where
          parent0_.id is not null
  </code></pre>
  
  <p>JSON (<em>no child</em>):</p>
  
  <pre><code>   [ {
      "id": 1
      "parentAttribute": "I am the parent"
      } ]
  </code></pre>
  
  <p>Any idea on how to force Jackson Hibernate4Module to serialize if present ?
  Thank you.</p>
  
  <p>I have a Spring Boot 1.3.1 back-office using JPA/hibernate for mapping entities. The front-end is an Angular2 application. The communication is a REST/JSON.
  My question is about forcing EAGER loading in some queries when I have a Lazy relationship.
  The <a href="https://stackoverflow.com/a/1668729/6385802" title="Use JOIN FETCH">solution using JOIN FETCH</a> helped me in DAO layer (Repositories). <em>The entity is now completely loaded in a single query as I want in controllers layer</em>. <strong>But the serialized JSON still incomplete due to Hibernate4Module</strong>.</p>
  
  <p>Bellow Hibernate4Module features can't help :-(</p>
  
  <ul>
  <li>FORCE_LAZY_LOADING</li>
  <li>USE_TRANSIENT_ANNOTATION</li>
  <li>SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS</li>
  <li>REQUIRE_EXPLICIT_LAZY_LOADING_MARKER</li>
  <li>REPLACE_PERSISTENT_COLLECTIONS</li>
  </ul>
  
  <p>Any idea is welcome. Thanks.</p>