Swift 4: With Codable `Generic parameter 'T' could not be inferred` : <p>I am getting the following error:</p>

<p><code>Generic parameter 'T' could not be inferred</code> </p>

<p>on line: <code>let data = try encoder.encode(obj)</code></p>

<p>Here is the code</p>

<pre><code>import Foundation

struct User: Codable {
    var firstName: String
    var lastName: String
}

let u1 = User(firstName: "Ann", lastName: "A")
let u2 = User(firstName: "Ben", lastName: "B")
let u3 = User(firstName: "Charlie", lastName: "C")
let u4 = User(firstName: "David", lastName: "D")

let a = [u1, u2, u3, u4]

var ret = [[String: Any]]()
for i in 0..&lt;a.count {
        let param = [
            "a" : a[i],
            "b" : 45
            ] as [String : Any]
    ret.append(param)
}


let obj = ["obj": ret]

let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try encoder.encode(obj) // This line produces an error
print(String(data: data, encoding: .utf8)!)
</code></pre>

<p>What am I doing wrong?</p>
