package com.bigcommerce.api;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Builds a JSON formatted String of the Form parameters.
 * 
 * @author Jenith Michael Raj
 * 
 */
public class Form {

	private Map<String, Object> parameters;

	private Form(Map<String, Object> parameters) {
		this.parameters = parameters;
	}

	public static Form create() {
		return create(null);
	}

	/**
	 * Factory method, creates an instance of a filter. Used to build URLs to
	 * collection endpoints.
	 */
	public static Form create(Map<String, Object> parameters) {
		return (parameters == null) ? new Form(new HashMap<String, Object>())
				: new Form(parameters);
	}

	public <T> void addParam(String parameter, T value) {
		this.parameters.put(parameter, value);
	}

	/**
	 * Converts the Form parameters into a JSON String that can be applied as
	 * POST/PUT parameters.
	 * 
	 * @return string
	 */
	public String toJson() {
		String json = null;
		try {
			json = buildJson(this.parameters);
		} catch (JSONException e) {
			// TODO Log
			e.printStackTrace();
		}
		return (json != null) ? json : "";
	}

	private String buildJson(Map<String, Object> data) throws JSONException {
		JSONObject json = new JSONObject();
		for (Entry<String, Object> pair : data.entrySet()) {
			json.put(pair.getKey(), pair.getValue());
		}
		
		return json.toString();
	}

}

@@ -75,94 +75,41 @@
 ap;%0A
-import java.util.Map.Entry;%0A%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject
+%0Aimport org.json.simple.JSONValue
 ;%0A%0A/
@@ -202,16 +202,19 @@
 hael Raj
+. Y
 %0A * %0A */
@@ -716,20 +716,23 @@
 oid addP
-aram
+roperty
 (String 
@@ -1037,20 +1037,16 @@
  catch (
-JSON
 Exceptio
@@ -1192,199 +1192,46 @@
 ta) 
-throws JSONException %7B%0A%09%09JSONObject json = new JSONObject();%0A%09%09for (Entry%3CString, Object%3E pair : data.entrySet()) %7B%0A%09%09%09json.put(pair.getKey(), pair.getValue());%0A%09%09%7D%0A%09%09%0A%09%09return json.to
+%7B%0A%09%09return JSONValue.toJSON
 String(
+data
 );%0A%09

Update Form.java