Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Feature.geometry optional #179

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions src/GeoJSON.Net.Tests/Feature/FeatureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@
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()
{
Expand Down Expand Up @@ -409,7 +441,7 @@
var feature = new Net.Feature.Feature(new Point(new Position(12, 123)));
Assert.DoesNotThrow(() =>
{
equal1 = feature == feature;

Check warning on line 444 in src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

View workflow job for this annotation

GitHub Actions / linuxBuild

Comparison made to same variable; did you mean to compare something else?

Check warning on line 444 in src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

View workflow job for this annotation

GitHub Actions / linuxBuild

Comparison made to same variable; did you mean to compare something else?

Check warning on line 444 in src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

View workflow job for this annotation

GitHub Actions / linuxBuild

Comparison made to same variable; did you mean to compare something else?

Check warning on line 444 in src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

View workflow job for this annotation

GitHub Actions / linuxBuild

Comparison made to same variable; did you mean to compare something else?

Check warning on line 444 in src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

View workflow job for this annotation

GitHub Actions / winBuild

Comparison made to same variable; did you mean to compare something else?

Check warning on line 444 in src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

View workflow job for this annotation

GitHub Actions / winBuild

Comparison made to same variable; did you mean to compare something else?

Check warning on line 444 in src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

View workflow job for this annotation

GitHub Actions / winBuild

Comparison made to same variable; did you mean to compare something else?

Check warning on line 444 in src/GeoJSON.Net.Tests/Feature/FeatureTests.cs

View workflow job for this annotation

GitHub Actions / winBuild

Comparison made to same variable; did you mean to compare something else?
equal2 = feature.Equals(feature);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "Feature",
"geometry": null,
"properties": {
"name": "Unlocalized Feature"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "Feature",
"properties": {
"name": "Unlocalized Feature"
}
}
2 changes: 1 addition & 1 deletion src/GeoJSON.Net/Feature/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down