title: Deserializing JSON from Hibernate
body: <p>I'm having a problem de deserializing a class in Spring Boot. When my controller tries to deserialize it, it crashes. Here is the class:</p>
  
  <pre><code>@Entity
  @Table(name="trash_cans")
  @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="id")
  public class TrashCan {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name="TRASH_CAN_ID")
      long id;
  
      @Column(name="TRASH_CAN_NAME")
      String name;
  
      @ManyToOne
      @JoinColumn(name="PLACE_ID")
      private Place place;
  
      @OneToMany(mappedBy="trashCan", targetEntity=TrashMeter.class, fetch=FetchType.LAZY)
      private List&lt;TrashCan&gt; trashMeterList;
  
      @OneToMany(mappedBy="trashCan", targetEntity=TrashSensor.class, fetch=FetchType.LAZY)
      private List&lt;TrashSensor&gt; trashSensorList;
  
      public TrashCan() {     
      }
  
      public TrashCan(long id, String name) {
          super();
          this.id = id;
          this.name = name;
      }
  
      [getters and setters]
  }
  </code></pre>
  
  <p>That depends on this one: </p>
  
  <pre><code>@Entity
  @Table(name="trash_sensor")
  @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="id")
  public class TrashSensor {
  
      @Id
      @Column(name="id")
      @GeneratedValue(strategy=GenerationType.AUTO)
      private long id;
  
      @Column(name="name")
      private String name;
  
      @Column(name="description")
      private String description;
  
      @ManyToOne
      @JoinColumn(name="TRASH_CAN_ID")
      private TrashCan trashCan;
  
      @OneToMany(mappedBy = "trashSensor", targetEntity = Measurement.class, fetch = FetchType.LAZY)
      private List&lt;Measurement&gt; measurementList;
  
      public TrashSensor() {
          super();
      }
  </code></pre>
  
  <p>And Trash Sensor Depends on this Class:</p>
  
  <pre><code>@Entity
  @Table(name="measurement")
  @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="id")
  public class Measurement {
  
      @Id
      @Column(name="id")
      @GeneratedValue(strategy=GenerationType.AUTO)
      private long id;
  
      @Column(name="value")
      private float value;
  
      @Column(name="last_measure")
      private LocalDateTime dateTime;
  
      @ManyToOne
      @JoinColumn(name="trash_sensor_id")
      private TrashCan trashSensor;
  
      public Measurement() {
      }
  
  }
  </code></pre>
  
  <p>My Controler: </p>
  
  <pre><code>@RequestMapping(value="/trashCan", method=RequestMethod.GET)
      public ResponseEntity&lt;Iterable&lt;TrashCan&gt;&gt; getPlaces(){
          Iterable&lt;TrashCan&gt; trashCanIterable = trashCansRepository.findAll();
  
          return new ResponseEntity&lt;&gt;(trashCanIterable, HttpStatus.OK);
      }
  </code></pre>
  
  <p>When I call the webservice, I get this error:</p>
  
  <blockquote>
    <p>Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: could not deserialize (through reference chain: java.util.ArrayList[0]-br.com.simplepass.cleanerway.domain.TrashCan["trashSensorList"]-org.hibernate.collection.internal.PersistentBag[0]-br.com.simplepass.cleanerway.domain.TrashSensor["measurementList"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: could not deserialize (through reference chain: java.util.ArrayList[0]-br.com.simplepass.cleanerway.domain.TrashCan["trashSensorList"]-org.hibernate.collection.internal.PersistentBag[0]-br.com.simplepass.cleanerway.domain.TrashSensor["measurementList"])</p>
  </blockquote>
  
  <p>I can't interpret this error <code>=/</code>. Any help with this problem greatly appreciated.</p>