title: Getting JsonMappingException while sending data to view
body: <p>I am trying to show DB data to my webpage.
  I have made following code when GET request to the <code>@RequestMapping(value = "/api/binder")</code>.</p>
  
  <p>but when get request came to this method it will fetch data (I have print on console and display well) but it doesn't map to my Java Script Ajax call, it's showing me an error.</p>
  
  <p>Following is my code for to fetch data :</p>
  
  <pre><code>    @Autowired
      IBinderViewRepository repository;
  
      @RequestMapping(method= RequestMethod.GET)
      public @ResponseBody
      List&lt;BinderResponse&gt; getBinders(){
          List&lt;BinderView&gt; binders = repository.getBinders();
          List&lt;BinderResponse&gt; responses = new ArrayList&lt;&gt;();
          ModelMapper mapper = Mapper.getInstance();
  
          for(int i = 0; i &lt; binders.size(); i++){
              System.out.println("In Loop");
              BinderResponse response = mapper.map(binders.get(i),BinderResponse.class);
              System.out.println("Data :: " + response.getBinderName());
              responses.add(response);
          }
          return responses;
      }
  </code></pre>
  
  <p>but it shows me following error :</p>
  
  <pre><code>HTTP Status 500 - Could not write JSON: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]-&gt;com.ngl.dto.outgoing.BinderResponse["valid"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]-&gt;com.ngl.dto.outgoing.BinderResponse["valid"])
  </code></pre>
  
  <p>Here is ajax call from knockout js :</p>
  
  <p><code>ajax.get('api/binder').done(function(response){ ... }</code></p>
  
  <p>Here <code>BinderView and BinderResponse</code> have same fields :</p>
  
  <pre><code>    private String binderName;
      private String binderAddress1;
  </code></pre>
  
  <p>and getter setter as well in both.
  and <code>repository.genBinders()</code> method bring data from DB.</p>
  
  <p>Here is insert method and works fine for me :</p>
  
  <pre><code>    @RequestMapping(method= RequestMethod.POST,consumes = "application/json")
      public @ResponseBody
      IWebApiResponse addBinder(@RequestBody AddBinderForm binder){
          .....
      }
  </code></pre>
  
  <p>Shall I have to put any <code>json annotation on my BinderResponse class ?</code></p>
  
  <p>I don't understand where am i wrong ?Anyone pleas guide me.</p>
  
  <blockquote>
    <p><strong>UPDATE :</strong></p>
  </blockquote>
  
  <pre><code>public class BinderResponse extends WebApiResponseBase {
      private String binderName;
      private String binderAddress1;
  
  public String getBinderName() {
          return binderName;
      }
  
      public void setBinderName(String binderName) {
          this.binderName = binderName;
      }
  
      public String getBinderAddress1() {
          return binderAddress1;
      }
  
      public void setBinderAddress1(String binderAddress1) {
          this.binderAddress1 = binderAddress1;
      }
  }
  </code></pre>
  
  <p>BinderView :</p>
  
  <pre><code>    public class BinderView extends BaseView {
          private String binderName;
          private String binderAddress1;
      public String getBinderName() {
              return binderName;
          }
  
          public void setBinderName(String binderName) {
              this.binderName = binderName;
          }
  
          public String getBinderAddress1() {
              return binderAddress1;
          }
  
          public void setBinderAddress1(String binderAddress1) {
              this.binderAddress1 = binderAddress1;
          }
  
  }
  </code></pre>
  
  <p>In console it prints data / BinderName :</p>
  
  <pre><code>In Loop
  Data :: ada
  In Loop
  Data :: tya
  </code></pre>
  
  <blockquote>
    <p><strong>New Update :</strong></p>
  </blockquote>
  
  <p>Here is <strong>BaseView</strong> :</p>
  
  <pre><code>@MappedSuperclass
  public abstract class BaseView implements IEntity {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue
      @Column(name="id")
      private long id;
  
      public long getId() {
          return id;
      }
  
      public void setId(long id) {
          if (this.id != 0 &amp;&amp; this.id != id) {
              throw new IllegalStateException(
                      "The ID must not be changed after it is set.");
          }
          this.id = id;
      }
  }
  </code></pre>
  
  <p>and In <strong>IEntity</strong> :</p>
  
  <pre><code>public interface IEntity  extends Serializable {
      long getId();
      void setId(long id);
  }
  </code></pre>
  
  <p><strong>WebApiResponseBase</strong> :</p>
  
  <pre><code>public class WebApiResponseBase implements IWebApiResponse {
  
      private String _uri;
  
      @Override
      public String getUri() {
          return _uri == null ? "" : _uri;
      }
  
      @Override
      public void setUri(String uri) {
          _uri = uri;
      }
  }
  </code></pre>