title: Trying to create a custom Json Deserializer for Microsoft.Spatial.GeographyPoint
body: <p>I am using Azure Location Service to retrieve certain locations. The Json I am returned is an array of objects that are populated like this (data omitted for privacy):</p>
  <pre><code>{
      &quot;Id&quot;: &quot;&quot;,
      &quot;Name&quot;: &quot;&quot;,
      &quot;Address&quot;: &quot;&quot;,
      &quot;PostCode&quot;: &quot;&quot;,
      &quot;Location&quot;: {
        &quot;Latitude&quot;: 123
        &quot;Longitude&quot;: -123,
        &quot;IsEmpty&quot;: false,
        &quot;Z&quot;: null,
        &quot;M&quot;: null,
        &quot;CoordinateSystem&quot;: {
          &quot;EpsgId&quot;: 123,
          &quot;Id&quot;: &quot;123&quot;,
          &quot;Name&quot;: &quot;ABC&quot;
        }
      }
    },
  </code></pre>
  <p>I am trying to deserialize into a <code>LookUpModel</code> object which has a Microsoft.Spatial.Geography point for its Location:
  <code>public GeographyPoint Location { get; set; }</code></p>
  <p>When I use the default newtonsoft json deserializer, I receive the following error: &quot;Could not create an instance of type Microsoft.Spatial.GeographyPoint. Type is an interface or abstract class and cannot be instantiated. Path '[0].Location.Latitude', line 11, position 17.&quot;</p>
  <p>Therefore I'm trying to create a custom Json Deserializer which will create a <code>GeographyPoint</code> (using <code>GeographyPoint.Create(Longitude = x, Latitude = y)</code> whenever the location node is hit. So far I have:</p>
  <pre><code>public class GeographyPointJsonConverter : JsonConverter
      {
          private readonly Type[] _types;
          public GeographyPointJsonConverter(params Type[] types)
          {
              _types = types;
          }
          public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
          {
              JToken t = JToken.FromObject(value);
              if (t.Type != JTokenType.Object)
              {
                  t.WriteTo(writer);
              }
              else
              {
                  JObject o = (JObject)t;
                  IList&lt;string&gt; propertyNames = o.Properties().Select(p =&gt; p.Name).ToList();
                  o.AddFirst(new JProperty(&quot;Keys&quot;, new JArray(propertyNames)));
                  o.WriteTo(writer);
              }
          }
          public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
          {
              throw new NotImplementedException(&quot;Unnecessary because CanRead is false. The type will skip the converter.&quot;);
          }
          public override bool CanRead
          {
              get { return false; }
          }
          public override bool CanConvert(Type objectType)
          {
              return _types.Any(t =&gt; t == typeof(GeographyPoint));
          }
      }
  </code></pre>
  <p>being called with: <code> var jsonData = JsonConvert.DeserializeObject&lt;LookUpModel[]&gt;(json, new GeographyPointJsonConverter(typeof(LookUpModel[])));</code></p>
  <p>However I cannot work out how I can successfully deserialize the Location information into a <code>GeographyPoint</code>? Is anyone able to point me in the right direction here please?</p>