title: @jsonignore not working as expected in spring mvc
body: <p>usercontroller.java</p>
  
  <pre><code>@RequestMapping("/listusersjson")
      public ResponseEntity&lt;Iterable&lt;User&gt;&gt; getListofUsersJson() {
          Iterable&lt;User&gt;   users = userService.listUser(); 
          return new ResponseEntity&lt;&gt;(users, HttpStatus.OK);
  
      }
  </code></pre>
  
  <p>user.java</p>
  
  <pre><code>@Entity
  public class User {
  
      @Id
      @GeneratedValue
      @Column(name="user_id")
      private Integer id;
  
      private String name;
  
      private String email;
  
      private String password;
  
      private int enabled;
  
      public User(Integer id) {
          super();
          this.id = id;
      }
  
  
      public User() {
          super();
      }
  
      @ManyToMany(cascade = CascadeType.ALL)
      @JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = {
              @JoinColumn(name = "role_id") })
      @JsonIgnore
      private List&lt;Role&gt; roless;
  
      @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
      @JsonIgnore
      private List&lt;Cart&gt; carts ;
  
  
      @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
      @JsonIgnore
      private List&lt;OrderDetails&gt; orderDetails ;
  
  }
  </code></pre>
  
  <p>Exception</p>
  
  <pre><code> HTTP Status 500 - Could not write JSON: failed to lazily initialize a collection of role: com.addtocart.dto.User.roless, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]-&gt;com.addtocart.dto.User["roles"]); nested exception is org.codehaus.jackson.map.JsonMappingException: failed to lazily initialize a collection of role: com.addtocart.dto.User.roless, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]-&gt;com.addtocart.dto.User["roles"])
  </code></pre>
  
  <p>Even though I have added the <code>@jsonignore</code> on all required fields where there is onetomany relationship and chances of lazyinitialization exception but still I am getting the above exception.I don't know what I am missing.</p>