title: c# JavaScriptConverter - how to deserialize custom property?
body: <p>I've got a class which has been serialized into JSON, and which I'm trying to deserialize into an object.</p>
  
  <p>e.g.</p>
  
  <pre><code>public class ContentItemViewModel
  {
      public string CssClass { get; set; }
      public MyCustomClass PropertyB { get; set; }
  }
  </code></pre>
  
  <p>the simple property (CssClass) will deserialize with:</p>
  
  <pre><code> var contentItemViewModels = ser.Deserialize&lt;ContentItemViewModel&gt;(contentItems);
  </code></pre>
  
  <p>But PropertyB gets an error...</p>
  
  <p>We added a JavaScriptConverter:</p>
  
  <pre><code>  ser.RegisterConverters(new List&lt;JavaScriptConverter&gt;{ publishedStatusResolver});
  </code></pre>
  
  <p>But when we added 'MyCustomClass' as a 'SupportedType', the Deserialize method was never called. However when we have ContentItemViewModel as the SupportedType, then Deserialize is called.</p>
  
  <p>We've got a current solution which looks something like this:</p>
  
  <pre><code>class ContentItemViewModelConverter : JavaScriptConverter
  {
  
      public override object Deserialize(IDictionary&lt;string, object&gt; dictionary, Type type, JavaScriptSerializer serializer)
      {
          var cssClass =  GetString(dictionary, "cssClass"); //I'm ommitting the GetString method in this example...           
          var propertyB= GetString(dictionary, "propertyB");
  
          return new ContentItemViewModel{    CssClass = cssClass , 
                                              PropertyB = new MyCustomClass(propertyB)}
      }
  
      public override IDictionary&lt;string, object&gt; Serialize(object obj, JavaScriptSerializer serializer)
      {
          throw new Exception("Only does the Deserialize");
      }
  
      public override IEnumerable&lt;Type&gt; SupportedTypes
      {
          get
          {
              return new List&lt;Type&gt;
                  {
                      typeof(ContentItemViewModel)
                  };
          }
      }
  }
  </code></pre>
  
  <p>But we'd prefer a simpler solution of only deserializing MyCustomClass, as there are a number of other fields which are on the ViewModel, and it seems a waste to have to edit this converter every time we change/add a property....</p>
  
  <p>Is there a way to Deserialize JUST PropertyB of type MyCustomClass?</p>
  
  <p>Thanks for your help!</p>