title: Json.Net serialize/deserialize dictionary class member with custom key type
body: <p>I have a problem trying to properly serialize/deserialize object with inner dictionary. Dictionary has some custom type <code>PairIntKey</code>  as a key. </p>
  
  <p>Code is the following:</p>
  
  <pre><code>public class MyClassWithDictionary
      {
          private Dictionary&lt;PairIntKey, List&lt;int&gt;&gt; _myDictionary = new Dictionary&lt;PairIntKey, List&lt;int&gt;&gt;();
  
          public Dictionary&lt;PairIntKey, List&lt;int&gt;&gt; MyDictionary
          {
              set { _myDictionary = value; }
          }
  
          public void AddElementsToMyDictionary(PairIntKey key, List&lt;int&gt; value)
          {
              _myDictionary.Add(key, value);
          }
      }
  
      public class PairIntKey : IEquatable&lt;PairIntKey&gt;
      {
          private int _value1;
  
          private int _value2;
  
          public int Value1
          {
              get { return _value1; }
          }
  
          public int Value2
          {
              get { return _value2; }
          }
  
          public PairIntKey(int value1, int value2)
          {
              _value1 = value1;
              _value2 = value2;
          }
  
          public override int GetHashCode()
          {
              return _value1 + 29 * _value2;
          }
  
          public bool Equals(PairIntKey other)
          {
              if (this == other) return true;
              if (other == null) return false;
              if (_value1 != other._value1) return false;
              if (_value2 != other._value2) return false;
              return true;
          }
  
          public override string ToString()
          {
              return String.Format("({0},{1})", _value1, _value2);
          }
  
      }
  </code></pre>
  
  <p>I serialize like this</p>
  
  <pre><code>public void SerializeAndDeserializeMyObject()
          {
              var myObject = new MyClassWithDictionary();
              myObject.AddElementsToMyDictionary(new PairIntKey(1, 1), new List&lt;int&gt; {5});
  
              var contractResolver = new DefaultContractResolver();
              contractResolver.DefaultMembersSearchFlags |= BindingFlags.NonPublic;
  
              string serializedItem = JsonConvert.SerializeObject(myObject,
                                                                  Formatting.Indented,
                                                                  new JsonSerializerSettings()
                                                                      {
                                                                          ContractResolver = contractResolver,
  
                                                                      });
  
              var deserializedItem = JsonConvert.DeserializeObject(serializedItem, typeof(MyClassWithDictionary),                                                                 new JsonSerializerSettings()
                                                                      {
                                                                          ContractResolver = contractResolver,
  
                                                                      });
  
  
              }
  </code></pre>
  
  <p><code>serializedItem</code> looks like</p>
  
  <pre><code>{
    "_myDictionary": {
      "(1,1)": [
        5
      ]
    }
  }
  </code></pre>
  
  <p>The problem is that <code>deserializedItem</code> has empty <code>MyDictionary</code> member. Its pretty obvious as soon as Json.Net doesn't know how to convert string  "(1,1)" into <code>PairIntKey</code> class instance.
  How to do a proper converter for that case? Or it should not be a converter?</p>