function toArray() {
        $result = array();
        $object_vars = get_object_vars($this);
       
        // copy each of this objects properties to an associative array
        // indexed by the property names
        foreach($object_vars as $key => $value) {
            if($value == null) { continue; }
            
            // if $value is an object, we can call toArray on it, and it 
            // should be serialized (isEmpty returns true) than we call 
            // toArray and insert the result in our array; 
            // otherwise we insert the value as-is
            if(gettype($value) == "object" && 
             is_subclass_of($value, 'AbstractJSONWrapper')) {
                if(!$value->isEmpty()) {
                    $result[$key] = $value->toArray();
                }
            } else {
                // TODO: maybe deal with com_maileon_api_json_AbstractJSONWrapper
                // derived classes that have 'non-serializable' properties
                $result[$key] = $value;
            }
        }
        
        // return the resulting array
        return $result;
    }