From 102a7b8ba30b32d6cdee4ef2b230530a3bc6d5a6 Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Mon, 3 Jul 2023 17:46:49 +0200 Subject: [PATCH 1/2] make Feature.properties optional * up to now it was required, but could be null --- src/GeoJSON.Net/Feature/Feature.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GeoJSON.Net/Feature/Feature.cs b/src/GeoJSON.Net/Feature/Feature.cs index 5624cbcf..3ced99e6 100644 --- a/src/GeoJSON.Net/Feature/Feature.cs +++ b/src/GeoJSON.Net/Feature/Feature.cs @@ -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; } /// From 2da16a76b6a42ab12cd56f236f7ba1a807273639 Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Wed, 14 Feb 2024 21:30:07 +0100 Subject: [PATCH 2/2] add a test case: deserializing a feature without any properties --- src/GeoJSON.Net.Tests/Feature/FeatureTests.cs | 14 ++++++++++++++ ...ests_Can_Deserialize_Feature_Without_Props.json | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_Without_Props.json diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs b/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs index 07259f93..1f1c2a10 100644 --- a/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs +++ b/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs @@ -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(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() { diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_Without_Props.json b/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_Without_Props.json new file mode 100644 index 00000000..5c798b6d --- /dev/null +++ b/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_Without_Props.json @@ -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 ] + ] + ] + } +} \ No newline at end of file