title: Bson array (de)serialization with Json.NET
body: <p>I am simply trying to serialize and deserialize a string array in Bson format using Json.NET, but the following code fails:</p>
  <pre><code>var jsonSerializer = new JsonSerializer();
  var array = new string [] { &quot;A&quot;, &quot;B&quot; };
  
  // Serialization
  byte[] bytes;
  using (var ms = new MemoryStream())
  using (var bson = new BsonWriter(ms))
  {
      jsonSerializer.Serialize(bson, array, typeof(string[]));
      bytes = ms.ToArray();
  }
  
  // Deserialization
  using (var ms = new MemoryStream(bytes))
  using (var bson = new BsonReader(ms))
  {
      // Exception here
      array = jsonSerializer.Deserialize&lt;string[]&gt;(bson);
  }
  </code></pre>
  <p>Exception message:</p>
  <blockquote>
  <p>Cannot deserialize the current JSON object (e.g. {&quot;name&quot;:&quot;value&quot;}) into type 'System.String[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.</p>
  <p>To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.</p>
  </blockquote>
  <p>How can I get this to work?</p>