拡張機能を使用して GeoJSON を逆シリアル化したいと考えています。
GeoJSON は線の座標を次のように持っています。
{ coordinates: [[longitude1, latitude1], [longitude2, latitude2, optional_altitude2]] }
これは高度を超えて拡張可能です。したがって、以下は LineString の有効な GeoJSON 座標です
{ coordinates: [[longitude1, latitude1], [longitude2, latitude2, optional_altitude2, { my_extension: something_something}]] }
したがって、クラスを次のように定義します。
public class GeoJSonCooridnateExtension
{
/// <summary>Gets type - should be "Feature".</summary>
[DataMember(Name = "Something", IsRequired = true)]
public string Something { get; internal set; }
}
public class GeoJSonGeometry
{
/// <summary>Gets type - should be "Feature".</summary>
[DataMember(Name = "type", Order = 0, IsRequired = true)]
public string GeometryType { get; internal set; }
/// <summary>Gets horizontal (west-east) position.</summary>
[DataMember(Name = "coordinates", Order = 1, IsRequired = true)]
public List<List<object>> Coordinates { get; internal set; }
}
シリアライザーを作成するとき、「GeoJSonCooridnateExtension」を「既知の型」として渡します。デシリアライザーは成功しますが、私が作成した型ではなく、汎用オブジェクトを配列に入れます。オブジェクト API を使用して汎用オブジェクト プロパティをクエリしようとしましたが、何も返されませんでした。DataContractJSonSerializer でそれを行うことさえ可能ですか?
以下のサンプル JSON を参照してください。
{
"type": "Feature",
"geometry":
{
"type": "LineString",
"coordinates":
[
[-35.480741083326052,47.926613991573959, null, {"Something":"my-value"}],
[-34.355741083326052,58.027854137187823],
[-27.605741083326055,49.776973283701281]
]
}
}