From 35b0106535419b3b90160bad43952b70d29eca4c Mon Sep 17 00:00:00 2001 From: Janus Weil <janus@gcc.gnu.org> Date: Sun, 7 Jul 2024 08:29:31 +0200 Subject: [PATCH 1/4] make Feature.geometry optional --- 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 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; } From 9dbb25fd45d0eaf89c17bccab5905985df73899d Mon Sep 17 00:00:00 2001 From: Janus Weil <janus@gcc.gnu.org> Date: Sun, 7 Jul 2024 18:54:23 +0200 Subject: [PATCH 2/4] add two test cases * deserializing a feature with NULL geometry * deserializing a feature without any geometry * the resulting feature object is identical for both cases --- src/GeoJSON.Net.Tests/Feature/FeatureTests.cs | 32 +++++++++++++++++++ ...eserialize_Feature_With_Null_Geometry.json | 7 ++++ ..._Deserialize_Feature_Without_Geometry.json | 6 ++++ 3 files changed, 45 insertions(+) create mode 100644 src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_With_Null_Geometry.json create mode 100644 src/GeoJSON.Net.Tests/Feature/FeatureTests_Can_Deserialize_Feature_Without_Geometry.json 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<Net.Feature.Feature>(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<Net.Feature.Feature>(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" + } +} From 6744136d460c8774ca33b63ad3f76d9fd4f072fa Mon Sep 17 00:00:00 2001 From: Janus Weil <janus@gcc.gnu.org> Date: Sun, 7 Jul 2024 19:15:55 +0200 Subject: [PATCH 3/4] amend .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From 7920534c2371204396a60ff78952432188cb1c96 Mon Sep 17 00:00:00 2001 From: Janus Weil <janus@gcc.gnu.org> Date: Sun, 7 Jul 2024 19:23:27 +0200 Subject: [PATCH 4/4] GHA: fix some deprecation warnings The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/ The following actions uses Node.js version which is deprecated and will be forced to run on node20: actions/checkout@v2. For more info: https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/ --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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