diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 04ecf93..f8df7ba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: linuxBuild: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup .NET Core @@ -32,7 +32,7 @@ jobs: winBuild: runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup .NET Core diff --git a/.gitignore b/.gitignore index 2704f99..2c27f4a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ node_modules *.csproj.user /TestResults .vscode +.mono /GoCompare.CustomerPreference/CustomerPreferenceService/Service.xml /GoCompare.CustomerPreference/CustomerPreferenceService/Properties/PublishProfiles/CustomerPreferenceService - Web Deploy.pubxml /GoCompare.CustomerPreference/CustomerPreferenceService/Properties/PublishProfiles/CustomerPreferenceService - Web Deploy.pubxml.user diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs b/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs index 1f1c2a1..1b4075f 100644 --- a/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs +++ b/src/GeoJSON.Net.Tests/Feature/FeatureTests.cs @@ -43,6 +43,38 @@ public void Can_Deserialize_Feature_Without_Props() Assert.AreEqual(GeoJSONObjectType.Polygon, feature.Geometry.Type); } + [Test] + public void Can_Deserialize_Feature_With_Null_Geometry() + { + var json = GetExpectedJson(); + + var feature = JsonConvert.DeserializeObject(json); + + Assert.IsNotNull(feature); + Assert.IsNotNull(feature.Properties); + Assert.IsTrue(feature.Properties.Any()); + Assert.IsTrue(feature.Properties.ContainsKey("name")); + Assert.AreEqual(feature.Properties["name"], "Unlocalized Feature"); + + Assert.IsNull(feature.Geometry); + } + + [Test] + public void Can_Deserialize_Feature_Without_Geometry() + { + var json = GetExpectedJson(); + + var feature = JsonConvert.DeserializeObject(json); + + Assert.IsNotNull(feature); + Assert.IsNotNull(feature.Properties); + Assert.IsTrue(feature.Properties.Any()); + Assert.IsTrue(feature.Properties.ContainsKey("name")); + Assert.AreEqual(feature.Properties["name"], "Unlocalized Feature"); + + Assert.IsNull(feature.Geometry); + } + [Test] public void Can_Serialize_LineString_Feature() { diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_With_Null_Geometry.json b/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_With_Null_Geometry.json new file mode 100644 index 0000000..5a194ff --- /dev/null +++ b/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_With_Null_Geometry.json @@ -0,0 +1,7 @@ +{ + "type": "Feature", + "geometry": null, + "properties": { + "name": "Unlocalized Feature" + } +} diff --git a/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_Without_Geometry.json b/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_Without_Geometry.json new file mode 100644 index 0000000..d16975e --- /dev/null +++ b/src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_Without_Geometry.json @@ -0,0 +1,6 @@ +{ + "type": "Feature", + "properties": { + "name": "Unlocalized Feature" + } +} diff --git a/src/GeoJSON.Net/Feature/Feature.cs b/src/GeoJSON.Net/Feature/Feature.cs index 3ced99e..f14d1ec 100644 --- a/src/GeoJSON.Net/Feature/Feature.cs +++ b/src/GeoJSON.Net/Feature/Feature.cs @@ -35,7 +35,7 @@ public Feature(TGeometry geometry, TProps properties, string id = null) [JsonProperty(PropertyName = "id", NullValueHandling = NullValueHandling.Ignore)] public string Id { get; } - [JsonProperty(PropertyName = "geometry", Required = Required.AllowNull)] + [JsonProperty(PropertyName = "geometry", Required = Required.Default)] [JsonConverter(typeof(GeometryConverter))] public TGeometry Geometry { get; }