title: How to serialize object to JSON string using classes from "org.json" package?
body: <p>I've tried to find any useful example to solve this easy task, however, nothing really helpful was found. I'm at the beginner level in Java and I definitely need some help.</p>
  
  <p>I have two simple Java classes:</p>
  
  <pre><code>private class FMList {
      public List&lt;FMItem&gt; items = new ArrayList();
      public long size = 0;
      public int dirs = 0;
      public int files = 0;
      public String path = "";
  }
  
  private class FMItem {
      public boolean is_dir = false;
      public String[] ascii = {};
      public String name = "";
      public String mode = "";
      public long size = 0;
      public long mtime = 0;
      public boolean ext = false;
      public String cache = "";
  }
  </code></pre>
  
  <p>My application (applet) creates an instance of <code>FMList</code>, sets data to object properties, and finally serializes the object to JSON string.</p>
  
  <p>First, I tried <a href="http://code.google.com/p/google-gson/" rel="nofollow">Google Gson</a> library. Simple <code>new Gson().toJson(fmList)</code> did the job perfectly, however my applet failed to start giving exceptions that Gson library has somewhat like security problems. Meanwhile, the applet was signed and all AccessController's were set.</p>
  
  <p>Then, I tried to use classes from <a href="http://www.json.org/java/" rel="nofollow">JSON official website</a>. There are no exceptions anymore but that simple <code>new JSONObject(fmList).toString()</code> gives <code>{}</code> only. I understand that it should be used somehow in a different way.</p>
  
  <p><em>What is the right way to serialize this simple object to JSON string using classes from <code>"org.json"</code> package?</em></p>
  
  <p>Thank you for help!</p>