title: Encode nil value as null with JSONEncoder
body: <p>I'm using Swift 4's <code>JSONEncoder</code>. I have a <code>Codable</code> struct with an optional property, and I'd like this property to show up as <code>null</code> value in the produced JSON data when the value is <code>nil</code>. However, <code>JSONEncoder</code> discards the property and does not add it to the JSON output. Is there a way to configure <code>JSONEncoder</code> so that it preserves the key and sets it to <code>null</code> in this case?</p>
  
  <h2>Example</h2>
  
  <p>The code snippet below produces <code>{"number":1}</code>, but I'd rather like it to give me <code>{"string":null,"number":1}</code>:</p>
  
  <pre><code>struct Foo: Codable {
    var string: String? = nil
    var number: Int = 1
  }
  
  let encoder = JSONEncoder()
  let data = try! encoder.encode(Foo())
  print(String(data: data, encoding: .utf8)!)
  </code></pre>