Implement a toJSON method for each asterix type to return the JSON serialized version of the type.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_result_distribution@1150 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABinary.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABinary.java
index db9ac03..47e23fc 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABinary.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABinary.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -74,4 +77,13 @@
     public String toString() {
         return "ABinary";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("ABinary", bytes);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABitArray.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABitArray.java
index 4178b5a..a27b05e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABitArray.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABitArray.java
@@ -14,6 +14,10 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -129,4 +133,17 @@
         sb.append(" ]");
         return sb.toString();
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONArray bitArray = new JSONArray();
+        for (int i = 0; i < intArray.length; i++) {
+            bitArray.put(intArray[i]);
+        }
+        json.put("ABitArray", bitArray);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABoolean.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABoolean.java
index 11b223a..85c35b6 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABoolean.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ABoolean.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -71,4 +74,13 @@
     public int hash() {
         return bVal.hashCode();
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("ABoolean", bVal);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ACircle.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ACircle.java
index 767f172..c7d946c 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ACircle.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ACircle.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -73,4 +76,16 @@
     public String toString() {
         return "ACircle: { center: " + center + ", radius: " + radius + "}";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONObject circle = new JSONObject();
+        circle.put("center", center);
+        circle.put("radius", radius);
+        json.put("ACircle", circle);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
index ea4c33b..b6b22fe 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.types.BuiltinType;
@@ -82,4 +85,13 @@
     public int getChrononTimeInDays() {
         return chrononTimeInDay;
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("ADate", chrononTimeInDay);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
index e72fd8f..081fa63 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.types.BuiltinType;
@@ -113,4 +116,12 @@
         return chrononTime;
     }
 
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("ADateTime", chrononTime);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADouble.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADouble.java
index 816b8be..582e192 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADouble.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADouble.java
@@ -14,6 +14,9 @@
  */

 package edu.uci.ics.asterix.om.base;

 

+import org.json.JSONException;

+import org.json.JSONObject;

+

 import edu.uci.ics.asterix.common.exceptions.AsterixException;

 import edu.uci.ics.asterix.om.types.BuiltinType;

 import edu.uci.ics.asterix.om.types.IAType;

@@ -70,4 +73,12 @@
         return hashCode();

     }

 

+    @Override

+    public JSONObject toJSON() throws JSONException {

+        JSONObject json = new JSONObject();

+

+        json.put("ADouble", value);

+

+        return json;

+    }

 }

diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADuration.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADuration.java
index 13f4a05..113751f 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADuration.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADuration.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.types.BuiltinType;
@@ -109,4 +112,15 @@
         return sbder.toString();
     }
 
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONObject duration = new JSONObject();
+        duration.put("months", chrononInMonth);
+        duration.put("milliseconds", chrononInMillisecond);
+        json.put("ADuration", duration);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AFloat.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AFloat.java
index a66e198..9804eb3 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AFloat.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AFloat.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -69,4 +72,13 @@
     public String toString() {
         return "AFloat: {" + value + "}";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("AFloat", value);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt16.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt16.java
index bd27f20..2be714d 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt16.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt16.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -59,4 +62,13 @@
     public String toString() {
         return "AInt16: {" + value + "}";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("AInt16", value);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt32.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt32.java
index b656a57..640bc0e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt32.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt32.java
@@ -14,6 +14,9 @@
  */

 package edu.uci.ics.asterix.om.base;

 

+import org.json.JSONException;

+import org.json.JSONObject;

+

 import edu.uci.ics.asterix.common.exceptions.AsterixException;

 import edu.uci.ics.asterix.om.types.BuiltinType;

 import edu.uci.ics.asterix.om.types.IAType;

@@ -84,4 +87,13 @@
     public int hash() {

         return hashCode();

     }

-}
\ No newline at end of file
+

+    @Override

+    public JSONObject toJSON() throws JSONException {

+        JSONObject json = new JSONObject();

+

+        json.put("AInt32", value);

+

+        return json;

+    }

+}

diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt64.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt64.java
index 193a4af..769d492 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt64.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt64.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -58,4 +61,13 @@
     public String toString() {
         return "AInt64: {" + value + "}";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("AInt64", value);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt8.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt8.java
index 87e5472..90135a3 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt8.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInt8.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -58,4 +61,13 @@
     public String toString() {
         return "AInt8: {" + value + "}";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("AInt8", value);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ALine.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ALine.java
index 0285825..dc420ed 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ALine.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ALine.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -66,4 +69,16 @@
     public String toString() {
         return "ALine: { p1: " + p1 + ", p2: " + p2 + "}";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONObject line = new JSONObject();
+        line.put("p1", p1);
+        line.put("p2", p2);
+        json.put("ALine", line);
+
+        return json;
+    }
 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ANull.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ANull.java
index be47b41..baaa00a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ANull.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ANull.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -52,4 +55,13 @@
     public String toString() {
         return "null";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("ANull", "null");
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AOrderedList.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AOrderedList.java
index 4f5effd..36a92f3 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AOrderedList.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AOrderedList.java
@@ -16,6 +16,10 @@
 
 import java.util.ArrayList;
 
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.AOrderedListType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -107,4 +111,17 @@
         sb.append(" ]");
         return sb.toString();
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONArray list = new JSONArray();
+        for (IAObject v : values) {
+            list.put(v.toJSON());
+        }
+        json.put("AOrderedList", list);
+
+        return json;
+    }
 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APoint.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APoint.java
index 8e261a2..8bb44eb 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APoint.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APoint.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -66,4 +69,16 @@
     public String toString() {
         return "APoint: { x: " + x + ", y: " + y + " }";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONObject point = new JSONObject();
+        point.put("x", x);
+        point.put("y", y);
+        json.put("APoint", point);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APoint3D.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APoint3D.java
index 29ef6cd..d15139a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APoint3D.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APoint3D.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -72,4 +75,17 @@
     public String toString() {
         return "APoint3D: { x: " + x + ", y: " + y + ", z: " + z + " }";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONObject point = new JSONObject();
+        point.put("x", x);
+        point.put("y", y);
+        point.put("z", z);
+        json.put("APoint3D", point);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APolygon.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APolygon.java
index 29e3727..ed21378 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APolygon.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/APolygon.java
@@ -14,6 +14,10 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -85,4 +89,17 @@
         sb.append(" ]");
         return sb.toString();
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONArray polygon = new JSONArray();
+        for (int i = 0; i < points.length; i++) {
+            polygon.put(points[i].toJSON());
+        }
+        json.put("APolygon", polygon);
+
+        return json;
+    }
 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ARecord.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ARecord.java
index 0d1f578..0035289 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ARecord.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ARecord.java
@@ -14,6 +14,10 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.visitors.IOMVisitor;
@@ -87,4 +91,19 @@
         sb.append(" }");
         return sb.toString();
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONArray record = new JSONArray();
+        for (int i = 0; i < fields.length; i++) {
+            JSONObject item = new JSONObject();
+            item.put(type.getFieldNames()[i], fields[i]);
+            record.put(item);
+        }
+        json.put("ARecord", record);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ARectangle.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ARectangle.java
index 51f06bf..d82d351 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ARectangle.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ARectangle.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -66,4 +69,16 @@
     public String toString() {
         return "ARectangle: { p1: " + p1 + ", p2: " + p2 + "}";
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONObject rectangle = new JSONObject();
+        rectangle.put("p1", p1);
+        rectangle.put("p2", p2);
+        json.put("ARectangle", rectangle);
+
+        return json;
+    }
 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AString.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AString.java
index 0f7c9c2..b1f2550 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AString.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AString.java
@@ -14,6 +14,9 @@
  */

 package edu.uci.ics.asterix.om.base;

 

+import org.json.JSONException;

+import org.json.JSONObject;

+

 import edu.uci.ics.asterix.common.exceptions.AsterixException;

 import edu.uci.ics.asterix.om.types.BuiltinType;

 import edu.uci.ics.asterix.om.types.IAType;

@@ -67,4 +70,13 @@
     public int hash() {

         return hashCode();

     }

+

+    @Override

+    public JSONObject toJSON() throws JSONException {

+        JSONObject json = new JSONObject();

+

+        json.put("AString", value);

+

+        return json;

+    }

 }

diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
index 7b66cf9..b97ed51 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
 import edu.uci.ics.asterix.om.types.BuiltinType;
@@ -98,4 +101,12 @@
         return chrononTime;
     }
 
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        json.put("ATime", chrononTime);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AUnorderedList.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AUnorderedList.java
index 764d05b..459ccf5 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AUnorderedList.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AUnorderedList.java
@@ -16,6 +16,10 @@
 
 import java.util.ArrayList;
 
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.AUnorderedListType;
 import edu.uci.ics.asterix.om.types.IAType;
@@ -107,4 +111,17 @@
         sb.append(" ]");
         return sb.toString();
     }
+
+    @Override
+    public JSONObject toJSON() throws JSONException {
+        JSONObject json = new JSONObject();
+
+        JSONArray list = new JSONArray();
+        for (IAObject v : values) {
+            list.put(v.toJSON());
+        }
+        json.put("AUnorderedList", list);
+
+        return json;
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/IAObject.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/IAObject.java
index 463154b..8ec036e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/IAObject.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/IAObject.java
@@ -14,6 +14,9 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.IAType;
 import edu.uci.ics.asterix.om.visitors.IOMVisitor;
@@ -29,4 +32,6 @@
     public boolean deepEqual(IAObject obj);
 
     public int hash();
+
+    public JSONObject toJSON() throws JSONException;
 }
\ No newline at end of file