title: Invalid type in JSON write in Swift Alamofire
body: <p>I am having issues sending my parameters over Alamofire.  This is the JSON that the server expects:</p>
  
  <pre><code>{
  “users”:[{“_id”:”1234567”}, {“_id”:”665543”}]
  }
  </code></pre>
  
  <p>Now, in my Swift code, this is how I’m trying to build out the above object:</p>
  
  <pre><code>let parameters = [“users” : users]
  return sendRequest(.PUT, url: “example.com", parameters: parameters)
  </code></pre>
  
  <p>where users is an array. Here is more info on what users is (I have taken out some of the other inherits to simplify):</p>
  
  <pre><code>class User : MyBase, CustomStringConvertible {
    var name: String
  
    var description : String {
       get{
            return ["_id" : self._id!].description
       }
   }
  }
  
  class MyBase {
    var _id: String?
  }
  </code></pre>
  
  <p>If I do a <code>debugPrint(users)</code>, this is what I get:</p>
  
  <pre><code>[“users”: [["_id": "1234567"], ["_id": "665543"]]]
  </code></pre>
  
  <p>And here’s the sendRequest method that does the Alamofire stuff:</p>
  
  <pre><code>static func sendRequest(method: Alamofire.Method, url: String, parameters: [String: AnyObject]?) {
          Alamofire.request(method, url, parameters: parameters as! [String: [User]], encoding: .JSON)
              .validate()
              .responseObject { (response: Response&lt;User, NSError&gt;) in
                  switch response.result {
                  case .Success(let value):
                      // do something
                  case .Failure(let error):
                      // do something else
                  }
          }
      }
  </code></pre>
  
  <p>And the error it throws on the Alamofire.request line is this:</p>
  
  <pre><code>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (MyApp.User)’
  </code></pre>
  
  <p>Ultimately, what I have is an array of user objects, and I need to send that to my server in the JSON format mentioned above. Being new to Swift, I’ve been struggling trying to figure this out, so any help is appreciated.</p>