title: retrieving data from database as json in spring boot
body: <p>I have a MySQL database and I want to retrieve some data as json.</p>
  
  <p>And I have an entity <code>Offre</code> wich has <code>@OneToMany</code> relation with the <code>AssociationCandidatOffre</code> entity.</p>
  
  <p>and I have an api which calles this method in my repository :</p>
  
  <pre><code>offreRepository.findAll();
  </code></pre>
  
  <h1>Offre entity :</h1>
  
  <pre><code>@Entity
  public class Offre implements Serializable {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "CODE_OFFRE")
      private Long codeOffre;
      private String titre;
  
      @OneToMany(mappedBy = "offre")
      private Collection&lt;AssociationCandidatOffre&gt; associationCandidatOffres;
  
      public Collection&lt;AssociationCandidatOffre&gt; getAssociationCandidatOffres() {
          return associationCandidatOffres;
      }
  
      public void setAssociationCandidatOffres(Collection&lt;AssociationCandidatOffre&gt; associationCandidatOffres) {
          this.associationCandidatOffres = associationCandidatOffres;
  
  
      }
       //... getters/setters      
      }
  </code></pre>
  
  <h1>AssociationCandidatOffre entity :</h1>
  
  <pre><code>@Entity
  public class AssociationCandidatOffre implements Serializable {
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private Long idAssociation;
      private String lettreMotivation;
      private String tarifJournalier;
      private Date dateDisponibilite;
  
      @ManyToOne
      private Candidat candidat;
  
      @ManyToOne
      private Offre offre;
      @JsonIgnore
      @XmlTransient
      public Candidat getCandidat() {
          return candidat;
      }
      @JsonSetter
      public void setCandidat(Candidat candidat) {
          this.candidat = candidat;
      }
      @JsonIgnore
      @XmlTransient
      public Offre getOffre() {
          return offre;
      }
      @JsonSetter
      public void setOffre(Offre offre) {
          this.offre = offre;
      }
  
      //... getters/setters
  }
  </code></pre>
  
  <p>the problem is when I call the api <code>/offres</code> to return me a json object I get this error message instead :</p>
  
  <pre><code>    Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: could not extract ResultSet (through reference chain: java.util.ArrayList[0]-&gt;com.***.Rekrute.entities.Offre["associationCandidatOffres"]); 
  nested exception is com.fasterxml.jackson.databind.JsonMappingException: could not extract ResultSet (through reference chain: java.util.ArrayList[0]-&gt;com.***.Rekrute.entities.Offre["associationCandidatOffres"])
  </code></pre>
  
  <p>when I use <code>@JsonIgnore</code> in the <code>getAssocationCandidatOffres</code> I dont get any errors but I want that association in the json result as well.</p>
  
  <p>Normally, this shouldn't generate any error since I have <code>@JsonIgnore</code> in the other side of the relation which is <code>getOffre()</code>.</p>
  
  <p>how can I solve this problem ?</p>