title: How to convert Arraylist to Json in Java
body: <p>I have an arraylist, the arraylist holds a bunch of Domain object. It's like below showed:</p>
  
  <pre><code>Domain [domainId=19, name=a, dnsName=a.com, type=0, flags=0]
  Domain [domainId=20, name=b, dnsName=b.com, type=0, flags=12]
  Domain [domainId=21, name=c, dnsName=c.com, type=0, flags=0]
  Domain [domainId=22, name=d, dnsName=d.com, type=0, flags=0]
  </code></pre>
  
  <p>My question is how to convert the <code>ArrayList</code> to JSON? The data format should be:</p>
  
  <pre><code>{  
  "param":{  
    "domain":[  
      {  
        "domid":19,
        "name":"a",
        "dnsname":"a.com",
        "type":0,
        "flags":
      },
      ...
    ]
  }
  </code></pre>