Deserializing JSON to a .net base class with JSON.net
I am trying to deserialize [GeoJSON][1] using the [JSON.net][2] library. The geometry component of each feature can be of many different types based on the "type" attribute value.

I need to deserialize the geometry component of this GeoJSON into a geometry object model like so:

    public abstract class Geometry { ... }

    public class Point : Geometry { ... }

    public class LineString : Geometry { ... }

    public class Polygon : Geometry { ... }

So based on the value of the "type" attribute, it will deserialize into the corresponding .net concrete type, but accessed via its base Geometry class.

Does the JSON.net library offer anything similar to the [KnownTypeAttribute][3] in WCF or [XmlElementAttribute][4] in XML Serialization that allows me to deserialize JSON to a base class with a set of known derived classes?


  [1]: http://geojson.org/geojson-spec.html
  [2]: http://json.codeplex.com/
  [3]: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.knowntypeattribute.aspx
  [4]: http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.aspx
Deserializing JSON to a .net base class with JSON.net
===

I am trying to deserialize [GeoJSON][1] using the [JSON.net][2] library. The geometry component of each feature can be of many different types based on the "type" attribute value.

I need to deserialize the geometry component of this GeoJSON into a geometry object model like so:

    public abstract class Geometry { ... }

    public class Point : Geometry { ... }

    public class LineString : Geometry { ... }

    public class Polygon : Geometry { ... }

So based on the value of the "type" attribute, it will deserialize into the corresponding .net concrete type, but accessed via its base Geometry class.

Does the JSON.net library offer anything similar to the [KnownTypeAttribute][3] in WCF or [XmlElementAttribute][4] in XML Serialization that allows me to deserialize JSON to a base class with a set of known derived classes?


  [1]: http://geojson.org/geojson-spec.html
  [2]: http://json.codeplex.com/
  [3]: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.knowntypeattribute.aspx
  [4]: http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.aspx