title: conversion of array list to json object string
body: <p>I have a model class method which returns a list of objects which contains all the registered user details. I want to fetch the list resturned by all() method and convert the data into JSON object and pass it to the view like a string. How can I do this conversion of this array list to JSON object? </p>
  
  <p>I was unable to do this by below: </p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  JSONObject json = new JSONObject();
  JsonNodeFactory jsonnode = JsonNodeFactory.instance;
  ObjectNode result = new ObjectNode(jsonnode);
  for (int i = 0; i &lt; list.size(); i++) {
      json.put(list.get(i).fname, list.get(i));
      System.out.println(json.get("fname"));
  }
  
  @Entity
  class Mydata extends Model {
  
      @Id
      public Long Id;
      public String fname;
      public String lname;
      public String city;
      public String state;
      /****************** READ/select OPERATION *****************/
      public static Finder &lt; Long, Mydata &gt; finder = new Finder(Long.class, Mydata.class);
  
      public static List &lt; Mydata &gt; all() {
          return finder.all();
      }
      public static void createuser(Mydata user) {
          user.save();
      }
  }
  </code></pre>