title: Serialize class with BsonDocument via JSON.NET or XML Serializer
body: <p>I want to return the following sample class by an ApiController, which is probably just JSON.NET serialized, but I want to avoid just converting the whole class to a json-string.</p>
  
  <pre><code>public class Report
  {
      [BsonId, JsonIgnore]
      public ObjectId _id { get; set; }
  
      public string name { get; set; }
  
      public BsonDocument layout { get; set; }
  }
  </code></pre>
  
  <p>Now I have looked at several ways but only one worked so far, which is creating a second class and map manually between the two by converting the layout-property to a json-string like this:</p>
  
  <pre><code>layout.ToJson();
  </code></pre>
  
  <p>This seems not very elegant and I'm wondering if there is a better way. None of the following ideas work for various reasons:</p>
  
  <pre><code>public class Report
  {
      [BsonId, JsonIgnore]
      public ObjectId _id { get; set; }
  
      public string name { get; set; }
  
      [JsonIgnore]
      public BsonDocument layout { get; set; }
  
      [JsonProperty(PropertyName = "layout")]
      public string layout2JSON()
      { 
          return layout.ToJson();
      }
  }
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>public class Report
  {
      [BsonId, JsonIgnore]
      public ObjectId _id { get; set; }
  
      public string name { get; set; }
  
      public BsonDocument layout 
      { 
          get 
          {
              return layout.ToJson();
          }
          set; 
      }
  }
  </code></pre>
  
  <p>I'm pretty new to C# and might easily miss obvious answers.</p>