         // TODO: handle status codes and header fields
         let response = NSHTTPURLResponse(URL: request.URL!, statusCode: 200, HTTPVersion: "", headerFields: nil)
         client.URLProtocol(self, didReceiveResponse: response!, cacheStoragePolicy: .AllowedInMemoryOnly)
-        let serializedObjects = serializableObjects?.serialize()
         
-        if let serializedObjects = serializedObjects as? [String: Any] {
-            let anyObjectDictionary = Dictionary(serializedObjects.map{ ($0, $1 as! AnyObject) })
-            let data = try! NSJSONSerialization.dataWithJSONObject(anyObjectDictionary, options: .PrettyPrinted)
-            
-            client.URLProtocol(self, didLoadData: data)
-        } else if let serializedObjects = serializedObjects as? [Any] {
-            let anyArrayDictionary = serializedObjects.map{ $0 as! [String: Any] }
-            let anyObjectDictionary = anyArrayDictionary.map{Dictionary($0.map{ ($0, $1 as! AnyObject) })}
-            let data = try! NSJSONSerialization.dataWithJSONObject(anyObjectDictionary, options: .PrettyPrinted)
-            
+        if let data = toData(serializableObjects?.serialize()) {
             client.URLProtocol(self, didLoadData: data)
         }
         

        KakapoServer.routes[urlString] = (.PUT, handler)
    }
    
}

        for (k, v) in pairs {
            self[k] = v
        }
    }
}

private extension SequenceType where Generator.Element == Any {
    func toData() -> NSData? {
        let anyArrayDictionary = flatMap{ $0 as? [String: Any] }
        let anyObjectDictionary = anyArrayDictionary.map{Dictionary($0.map{ ($0, $1 as! AnyObject) })}
        let data = try? NSJSONSerialization.dataWithJSONObject(anyObjectDictionary, options: .PrettyPrinted)
        
        return data
    }
}

private extension CollectionType where Self: DictionaryLiteralConvertible, Generator.Element == (String, Any)  {
    func toData() -> NSData? {
        print(self)
        let dict = Dictionary(map { ($0, $1 as! AnyObject) })
        let data = try? NSJSONSerialization.dataWithJSONObject(dict, options: .PrettyPrinted)
        
        return data
    }
}

