Skip to content

Commit

Permalink
Merge pull request #167 from janusw/feature_properties_optional
Browse files Browse the repository at this point in the history
make Feature.properties optional
  • Loading branch information
xfischer committed Feb 28, 2024
2 parents 16cb756 + 2da16a7 commit 36be431
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/GeoJSON.Net.Tests/Feature/FeatureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public void Can_Deserialize_Point_Feature()
Assert.AreEqual(GeoJSONObjectType.Point, feature.Geometry.Type);
}

[Test]
public void Can_Deserialize_Feature_Without_Props()
{
var json = GetExpectedJson();

var feature = JsonConvert.DeserializeObject<Net.Feature.Feature>(json);

Assert.IsNotNull(feature);
Assert.IsNotNull(feature.Properties);
Assert.IsEmpty(feature.Properties);

Assert.AreEqual(GeoJSONObjectType.Polygon, feature.Geometry.Type);
}

[Test]
public void Can_Serialize_LineString_Feature()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[ 4.8892593383789062, 52.370725881211314 ],
[ 4.8952674865722656, 52.3711451105601 ],
[ 4.8920917510986328, 52.369310952782627 ],
[ 4.8892593383789062, 52.370725881211314 ]
]
]
}
}
2 changes: 1 addition & 1 deletion src/GeoJSON.Net/Feature/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Feature(TGeometry geometry, TProps properties, string id = null)
[JsonConverter(typeof(GeometryConverter))]
public TGeometry Geometry { get; }

[JsonProperty(PropertyName = "properties", Required = Required.AllowNull)]
[JsonProperty(PropertyName = "properties", Required = Required.Default)]
public TProps Properties { get; }

/// <summary>
Expand Down

0 comments on commit 36be431

Please sign in to comment.